I am new to React. Whenever I use npx create-react-app, it takes too long to download all the packages like "react, react-dom and react-scripts". Is it what happens every time or is there something that I can do to so that it doesn't take too long every time.
There are few factors which might have an impact on the performance of npm or npx commands in general.
Hard disks (mostly 5400RPM) ones bottleneck the I/O performance and thus causing installation process to slow down.
Internet connectivity issues - slow internet or high latency.
The terminal used also plays a crucial role. For example, Git Bash is known to have better performance than the Command Prompt on Windows platform.
Solution
Install CRA globally. npm install -g create-react-app and create-react-app my-app. Make sure you regularly update the package to ensure latest patches are applied.
Optionally, You can try OS level optimizations such as disk defragmentation to ensure there are no bottlenecks. Upgrading to an SSD would yield better performance.
You can use Yarn which in my experience, has better I/O performance. Similar to npx, Yarn has yarn create. You can do yarn create react-app my-app to create a React app.
npx always uses the latest version so it downloads packages each time you want to create new app so you should check your connection, otherwise you can use npm install -g create-react-app, it is not recommended though. see instructions for older npm versions
So, there are two fixes for this,
FIX 1:
This problem is observed with 12.16.2-x64.msi node version. If you installed x64 version then you just need to uninstall this version and install x32 bit version. Or try updating to the latest version.This fix should solve your problem.
FIX 2:
If you don't want to reinstall the node and continue with the current version then this fix would work.
Open a new cmd window and run resmon command. This command opens resource monitor and you would see something like this -
Once you could see the resource monitor. You need to start looking for cmd.exe processes (because there would be more than one cmd.exe based on how many windows you have got open) which are suspended.
If you find any cmd.exe suspended resume it. Your cmd process would also get resumed. There might be a case where cmd again stops, you just follow the above steps again.
Sometimes you may need to resume cmd.exe multiple times if it's suspense. And make sure you disable your anti-virus, it may prevent creating react npm app.
You might use local cache for npm packages. There is an open source cache, should be relatively straightforward to use. Install the cache software, and configure it. Basically it uses disk space, to trade for faster speed. If the bus (net) betwene your machine and the cache is faster than your Internet connection to npm repository, the cache is useful.
These caches act as in-between, they sit between you (your "yarn" or "npm" which wants to install a package) and the npm repository. The cache checks, whether it already has the package on its disk, and if so, serves it faster than the actual npm repository. Check out eg:
https://github.com/mixu/npm_lazy
Install react globally using the following command
npm install -g create-react-app
I faced the same issue and able to fix it like below.
Issue:
My organisation had set different repository URL in the global config when I run setup scripts for dev environment.
I was using work laptop to do something else and it was the problem.
How to check
Run this command
cat ./~npmrc
You should see something like this
registry=https://blah blah/npm-all/
change this to default registry by running the command
npm config set registry https://registry.npmjs.org/
check the same
cat ./~npmrc
Now run the command to create react app
npx create-react-app --template cra-template-rb app-name
As a beginner to create several sample react apps, I followed the following method to avoid the delay and save disk space by not duplicating the node_modules folder.
Create your first react app my-react-app in the usual way.
When you want to create another project, create just a folder say new-react-app first.
Open the my-react-app folder and copy everything except the node_modules folder to the new app folder.
Cut and paste the node_modules folder into the new folder. (Cut and paste is instantaneous and it avoids duplication)
now run 'npm start' in the new folder.
For completeness (not needed for example projects), edit the package.json and package-lock.json files to change the names to new-react-app.
package.json:
{
"name": "new-react-app", //"my-react-app",
...
package-lock.json:
{
"name": "new-react-app", //"my-react-app",
...
"packages": {
"": {
"name": "new-react-app", //"my-react-app",
...
If you want to run the old project again, cut and paste the node_modules to that folder and run 'npm start' there.
Periodically remove my-react-app and create a new my-react-app. Follow the same method till it works!
run resmon command from command line
look for the cmd process if cmd process is suspended the resume the process, it worked for me.
Related
I was working with brownie and everything was working smoothly, launched my first useDapp app and it was a lot of fun. I wanted to see what truffle was about and installed it via npm and there were a bunch of warnings and it didn't seem smooth when it came to functionality so I might have installed it via yarn, expecting the package installer to fix things. It worked for a while then it started to timeout upon migration with tested code that used to launch perfectly fine? I thought it might of been a bug or some form of overlapping installation. I moved on to hardhat and installed it via NPM and it wouldn't compile, so I installed it via Yarn and it compiled fine. I went on to creating a new file and accidentally hit Esc when it was initializing a new file and setting the root. Somewhere in between there I tried to install the shorthand and it didn't work. It only opened a Windows help window instead of call hardhat when I typed hh --help. After that I couldn't call hardhat via yarn hardhat nor npx hardhat outside of the file....the file that previously wouldn't compile was still able to compile via npx hardhat compile?
It sometimes says "module not found", other times it says something about local installation.
I kind of got frustrated and wanted to play with react a little more and when I went to start yarn I got an error message. I followed the prompt and it didn't work, I googled it and had no luck with their common resolutions. I tried to upgrade eslint and even install 7.11.0 and it keeps saying I have version 5.16.0?.
EDIT: not sure if it is relevant, I tried to update my yarn to 1.22.17 and it said it did, although it says im running 1.22.15.
windows 7
node = v12.13.0
npm =6.12.0
The react-scripts package provided by Create React App requires a dependency:
"eslint": "^7.11.0"
Don't try to install it manually: your package manager does it automatically.
However, a different version of eslint was detected higher up in the tree:
C:\Users\Nancy\node_modules\eslint (version: 5.16.0)
Manually installing incompatible versions is known to cause hard-to-debug issues.
If you would prefer to ignore this check, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project.
That will permanently disable this message but you might encounter other issues.
To fix the dependency tree, try following the steps below in the exact order:
1. Delete package-lock.json (not package.json!) and/or yarn.lock in your project folder.
2. Delete node_modules in your project folder.
3. Remove "eslint" from dependencies and/or devDependencies in the package.json file in your project folder.
4. Run npm install or yarn, depending on the package manager you use.
In most cases, this should be enough to fix the problem.
If this has not helped, there are a few other things you can try:
5. If you used npm, install yarn (http://yarnpkg.com/) and repeat the above steps with it instead.
This may help because npm has known issues with package hoisting which may get resolved in future versions.
6. Check if C:\Users\Nancy\node_modules\eslint is outside your project directory.
For example, you might have accidentally installed something in your home folder.
7. Try running npm ls eslint in your project folder.
This will tell you which other package (apart from the expected react-scripts) installed eslint.
If nothing else helps, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project.
That would permanently disable this preflight check in case you want to proceed anyway.
P.S. We know this message is long but please read the steps above :-) We hope you find them helpful!
error Command failed with exit code 1.
Kind of embarrassing, the answer was in the error message.
6. Check if C:\Users\Nancy\node_modules\eslint is outside your project directory.
For example, you might have accidentally installed something in your home folder.
Hardhat set root in the wrong directory and I ended up with a node_module folder in a parent directory that was messing things up
Reinstalled truffle globally via yarn add global truffle and it ran smoothly. Evidently, truffle acts up with certain NPM versions.
Hardhat doesn't seem to support global installations yet. Its been working fine being locally installed into each separate hardhat project via yarn add -D hardhat
I haven't been able to get the shorthand to work without invoking yarn first, such as yarn hh <command>
Appearing out of nowhere, this error has me stomped. It appears any time I try to import a css file, whether in full or as a module.
E.g.
import "./index.css"
or
import styles from "./button.module.css"
It MAY have been due to the latest macOS beta at least it seems to have coincided with its release. I tried rolling back from it, but that didn't work.
Failed to compile
./src/index.css (./node_modules/css-loader/dist/cjs.js?modules=true!./node_modules/style-loader/dist/cjs.js!./node_modules/css-loader/dist/cjs.js??ref--6-oneOf-4-1!./node_modules/postcss-loader/src??postcss!./src/index.css)
CssSyntax error: Unknown word (1:1)
> 1 | var api = require("!../node_modules/style-loader/dist/runtime/injectStylesIntoStyleTag.js");
| ^
2 | var content = require("!!../node_modules/css-loader/dist/cjs.js??ref--6-oneOf-4-1!../node_modules/postcss-loader/src/index.js??postcss!./index.css");
3 |
This error occurred during the build time and cannot be dismissed.
I've tried manually adding web pack, checked everything for syntax errors, re-installed the whole repo, went back several commits and so on. Nothing seems to do anything. Happy to supply more context.
(I found one other person mentioning the same problem on SO 15 hours ago, but he hadn't supplied debugging information so the ticket was closed).
Note: The same codebase runs perfectly well on my MacBook, no problems!
It's seems like your npm project setup is broken. This type of problem famously called Failed to compile generally occurs when we are moving one branch to another branch more often and we sometimes forgot to do npm install and continue to work on another branch which has new packages without doing npm install and many more cases which is very hard to tell that in which cases your npm setup is broken.
There are couple of ways of solving this issue.
First way
Delete the node_modules directory and package-lock.json file.
Close the editor and open it again and in new terminal do npm i. Then check whether it is compiled or not.
If that didn't work then follow the second way.
Second way
Clear the npm cache forcefully of your project setup.
npm cache clear -f
Then restart the system for closing all the node service for this session. After restart do npm i and check again.
If that didn't work then follow the third way which I think that fail compilation issue will be easily solved.
Third way
Just clone your project again in another directory and do npm install.
Can you try this?
👉 Delete these folders: node_modules and package-lock.json.
(You can also delete a cache folder if there is)
🚧 Run this Commands:
With yarn: yarn
With npm: npm install
👋 You can also try to change your import method:
import * as styles from ...
This might help hopefully!
The code is right. There may not be a problem with code.
The steps mentioned below might help:
Delete node_modules folder.
run npm install
run npm cache clean -f (try without -f first)
*first 2 steps worked for me.
I am working on react application and have less Internet, Every time creating a new react-app I should do npx create-react-app which downloads about 185 MB of files.
FIles Includes node_modules,src,public etc. Can I just copy and paste these basic folders from one folder to another?
what are the circumstances if I use it?
Is there any problem that I will face in the future?
While coping whole node_modules and then running npm install in the new directory should theoretically work fine (while speeding up the dependency install significantly), if you have a problem of slow internet, or low data, I’d personally recommend installing local npm proxy (registry). See eg. https://verdaccio.org/docs/en/what-is-verdaccio.html
I wanted to create a new react app using the create-react-app script. I still had a global version installed which is not supported anymore so I uninstalled the global version and tried creating a new one like this:
npx create-react-app myapp
I then got an error of no template used and that I probably use an older version of create-react-app. I read online and this DID work:
npx --ignore-existing create-react-app myapp
I read that it means I still got an older version even though I did uninstall the global version. So how do I remover any other older version of create-react-app?
The following steps solved the problem of removing an old version and creating a create-react-app.
1 Check version of create-react-app, using npx create-react-app -V.
2 Uninstall any global version of create-react-app, using either npm uninstall -g create-react-app or yarn global remove create-react-app.
3 View the contents of your machine _npx folder, each folder inside represents a version of node installed. Use ls -a /Users/<username>/.npm/_npx/.
4 View the version of create-react-app in a node version found in step 3 in the package.json file. Example nano /Users/<username>/.npm/_npx/c67e74de0542c87c/package.json.
5 Delete the node version folder. Example rm -rf /Users/<username>/.npm/_npx/c67e74de0542c87c. It will get recreated when you run step 6. Alternatively, you can rename the folder to be safe.
6 Create react app. npx create-react-app my-app. You should see the prompt to proceed app creation.
The npx is a tool to execute packages and npm is a tool mainly used to install packages. That's means if you want to execute a package without installing it on your computer and then launch it you can use npx directly.
Uninstall the library globally
Use npm uninstall -g create-react-app then check if is it removed successfully from your machine using which create-react-app. If still exist delete it manually.
Linux
rm -rf /usr/local/bin/create-react-app
-r -- attempt to remove the file hierarchy rooted in each file argument i.e. recursively remove subdirectories and files from the specified directory.
-f -- attempt to remove the files without prompting for confirmation, regardless of the file’s permissions
Windows
del /f/s/q C:\nodejs\node_modules\npm\bin\create-react-app > nul
rmdir /s/q C:\nodejs\node_modules\npm\bin\create-react-app
/f -- forces the deletion of read-only files.
/q -- enables quiet mode. You are not asked if it is ok to delete files (if you don't use this, you are asked for any file in the folder).
/s -- runs the command on all files in any folder under the selected structure.
Finally you able to use the last version with npx create-react-app myapp.
If someone in the future finds this and the above solutions don't help, I found a fix for myself.
I tried everything including the npm uninstall -g create-react-app which seemingly did nothing.
Then I finally found this from an old installation: C:\Users\<username>\AppData\Roaming\npm\
which had 2 react related files, named along the lines of create-react-app.cmd or something similar. Delete anything related to react from that folder.
Then in the same path delete this folder:
C:\Users\<username>\AppData\Roaming\npm\node_modules\create-react-app
If you had none of the above in your roaming folder, then your issue is elsewhere. The above files must have stayed from an old npm react installation which the uninstall command doesn't delete for some reason.
This fixed all problems for me though, and I was finally able to create a functioning project with npx create-react-app.
All the advice tells us remove the globally installed old version of create-react-app - but apparently it was a non-global existing installation that was causing the problem for me.
I had success with
npm uninstall create-react-app
(leaving out the -g flag).
I have no idea where it was, but apparently it is gone now :)
I was running into this on my MB Pro 2012 with Mojave (10.14.6) and tried a bunch of different things after the recommended solutions of
Please remove any global installs with one of the following commands:
- npm uninstall -g create-react-app
- yarn global remove create-react-app
I tried switching to each of my node versions using nvm one at a time and running both of these. I tried uninstalling all of the node versions I had. I ran
which create-react-app
And got nothing.
I tried to see if I could sidestep like the Original Poster, but when I ran
npx --ignore-existing create-react-app myapp
I got an error message saying that the ignore-existing option has now been disabled.
Some posts were mentioning an issue with npm's cache so I ran
nvm cache clear
But no dice. I was reading something other posts and saw some mentions of using homebrew to uninstall node, so I started going through that route:
brew doctor
Then
brew update
Then
brew upgrade
After that, I thought maybe it was installed in the system version of node and that nvm was hiding it from me. So, to get access to system node, I ran
nvm deactivate
Then I ran
which create-react-app
and I again got nothing. Finally, I tried to actually run the command using the system version of node
npx create-react-app my-app
This time, I got:
Need to install the following packages:
create-react-app
Ok to proceed? (y) y
Creating a new React app in /Users/my_username...
It went through with the install this time. Then when I opened another terminal with nvm activated and was able to run
npx create-react-app trying-again
Finally, it worked.
TLDR;
nvm deactivate
npx create-react-app my-app
# say yes when it asks you to install
# close that terminal and open another and you should be able to use the command as normal
Okay, the title might be confusing but I think my problem is pretty easy to explain with just the terminal code. My questions are below the code wall. emphasized text
[fsevents] Success: "/Users/Name/my-app/node_modules/fsevents/lib/binding/Release/node-v64-darwin-x64/fse.node" already installed
Pass --update-binary to reinstall or --build-from-source to recompile
+ react-dom#16.6.3
+ react-scripts#2.1.1
+ react#16.6.3
added 1768 packages from 678 contributors and audited 35639 packages in 81.268s
found 0 vulnerabilities
Initialized a git repository.
Success! Created my-app at /Users/macbookpro/my-app
Inside that directory, you can run several commands:
npm start
Starts the development server.
npm run build
Bundles the app into static files for production.
npm test
Starts the test runner.
npm run eject
Removes this tool and copies build dependencies, configuration files
and scripts into the app directory. If you do this, you can’t go back!
We suggest that you begin by typing:
cd my-app
npm start
So, how do I safely terminate this, and then turn it back on? Or does it need to stay running, and if it's terminated, need to be reinstalled with the "npx create-react app" command?
I guess I'm just wondering how to access "that directory."
I understand it's probably a super basic question, but it would help me get a grip on managing my react app.
Thank you!!
terminate and turn it back on
You can terminate the project with CTRL + C or CTRL + Z.And after the termination, you can feel free to restart it.
Assuming your project runs at port 3000,if you terminal your project, you won't be able to get your project in the browser.
If you want to get your project like in http://localhost:3000, you need to make the project stay running.
npx command
There is no need to "npx create-react app" again. "npx create-react-app my-app" command will install create-react-app command globally but momentarily, it was only needed when initial project.
access "that directory"
I think the message you post above has told you.
We suggest that you begin by typing:
cd my-app
npm start
If you choose npm start the watcher will be continuosly running for development process.. you can stop it pressing CTRL + C twice on terminal.
npm run build runs once and stops alone generating files for production (compiled, minified).
Actually after installation completed, you don't need to terminate it.
To enter the project directory, simply type cd my-app
Then to start the development server type npm start
it will take few seconds to bring you to the browser (my-app project opened).
You may like to see the address bar of the browser to know the running port of development server.
When you need to stop the server just press ctrl + c
If you forget the project directory's location in mac, you can find by mdfind kind:folder "my-app"
Optional: If you use Visual Studio Code then you can type code . being inside the project directory to open up the full project directory with VS Code.