npm update does nothing - reactjs

I am trying to update a specific npm package - "react-beautiful-dnd" although I don't think there is a problem with it. When I run "npm -v react-beautiful-dnd" in my project's directory, I can see that it's "6.4.1". I inherited the project, so the version is probably the latest stable one at the time. I wanted to update it to the newest one - 10.0.0, so the first thing I did was changing the version in package.json to the desired and then running npm install (without --save, wisely or not).
Everything went through fine, but I when I run "npm -v ..." it still shows the same version. From what I know, the stable version of the package is much higher than 6.4.1, so I don't have a clue what's up with that. When I run npm list -g and try to find the package through cmd + f, I don't even have it on the list, so it's likely not a problem with that.
Any ideas?

Updating local packages
Navigate to the root directory of your project and ensure it contains a package.json file:
cd /path/to/project
In your project root directory, run the [update][npm-update] command:
npm update
To test the update, run the [outdated][npm-outdated] command. There should not be any output.
npm outdated
you can also check out npm package update Document.

Related

Simple NPM Question Re-updating local react project after other dev added new package

I just started working with vscode and npm/git. Someone on my team added a package and I did a pull to get his latest changes which put that package in my package.json file. When I ran the project I got errors for a module not being found. Obviously I need to install that package locally. Do I simply use npm install w/no arguments to get it? Or do I install it manually myself with npm install and version info? I ask because I don't know if npm install w/no args will create a new package.json or cause any issues.
What is the correct way to get a new package installed that someone added in the repo?
npm install can be run as many times as you like, and is what you should be doing here :)
npm install's purpose is to get your node_modules folder up-to-date with whatever is written in package.json
So, if your colleague has changed package.json (by installing something new and pushing the change to git), you can just run the command again to get up-to-date.
Provided you haven't directly fiddled with any files in node_modules (this folder should be left alone), it is always safe to run npm install as many times as you like, even if nothing has changed.

npm ERR! Response timeout while trying to fetch https://registry.npmjs.org/react-is (over 30000ms)

When I want to create a react app I'm encountering the following error:
npm ERR! Response timeout while trying to fetch https://registry.npmjs.org/react-is (over 30000ms)
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\info\AppData\Roaming\npm-cache\_logs\2020-04-23T02_54_45_865Z-debug.log
Aborting installation.
npm install --save --save-exact --loglevel error react react-dom react-scripts cra-template has failed.
Deleting generated file... package.json
Deleting app2/ from C:\Users\info
Done.
Sounds like you have a slow connection. Try increasing the timeout from 30s to 60s by adding this to your .npmrc file:
timeout=60000
You could also try adding
prefer-offline=true
if you are trying to save bandwidth or have a slow connection
Note: if you don't have an .npmrc file setup yet, you can create one here
for Windows: C:\Users\{username}\.npmrc
for Mac/Linux ~/.npmrc
Or you can create one in the same directory as your project's package.json file.
I had a slow connection and I updated the timeout value to .npmrc using:
npm set timeout=100000
And to check if the value is updated (Mac): vi ~/.npmrc
Users are extremely likely to face this issue if they are on a slow internet connection. To counter this, you need to increase the timeout in the npm's config file. And here's how to do it:
Find the .npmrc file (located in the nodejs installation folder; in my case, it's in F:\Installations\nodejs\node_modules\npm folder. But for you, it might be in C:\program files folder).
Open the .npmrc file and append this line: timeout=240000 (usually it is 60 seconds I suppose, but since my connection was way slower therefore, I had to increase it to 240 seconds or 4 minutes, you can keep it 120000 for 120seconds)
Save the file
Since create-react-app fails midway, it can easily break npm's package.json file thus leading to this sort of issue:
Unexpected end of JSON input while parsing near
Therefore, before running the npx create-react-app, run the following command: npm cache clean --force as it cleans the cache and (i think) repairs the package.json file.
I was facing the same issue. I Solved it like this:
create a new file with no name just an extinction of .npmrc
open this file in any editor and type timeout = 90000
save the file and in you terminal type
npm cache clean --force
npm install create-react-app
npx create-react-app ./
Note: this error occurs because of slow internet speed
This error occurs due to slow internet connection. Try installing when you get a better speed. If better speed doesn't solve your problem try this.
npm cache verify
npm cache clean --force
I enabled IIS and the issue was solved for me:
do to Control Panel -> Programs -> Programs and Features
click on Turn Windows features on and off
make sure the Internet Information Services is checked
click OK and wait for some minutes
I was facing the same issue when create a react-app using npx create-react app . And i fixed my problem by running the following command.
npm cache clean --force
I hope you find this helpful
I fixed the problem by setting timeout in user local .npmrc file to
timeout=600000
90000 is not enough for downloading many packages for projects with lot dependencies in package.json
In case you are still running into this issue below with the error:
Invalid response body while trying to fetch
https://registry.npmjs.org/eslint-config-react-app: Socket timeout
Run this script: npm install react --registry=https://registry.npmjs.org
and then npx create-react-app mypp
for your react app installation. Happy coding
I fixed the problem by running:
npm config set registry "http://registry.npmjs.org" --global
It appears the problem is related to the following post:
npm install gets stuck at fetchMetadata
And #CptUnlucky's solution worked for me on macOS Catalina 10.15.7, node v16.0.0, npm v7.12.2, nvm v0.38.0
I was facing the same issue and I solved it by enabling the Internet Information service (IIS) feature of the window.
Enabling the IIS
Steps:
Windown + r
Type appwiz.cpl and click OK
click on Turn window features on or off (on the Left top side)
wait some seconds and check the Internet information service option
Now wait until window apply changes.
create project again.
I have faced the same issue. I tried all solutions over StackOverflow or Github discussions but nothing worked.
I changed the .npmrc file under the Users folder in C in Windows and changed the timeout from 30000 to 90000. See if 60000 works!
In my case it was the issue related to npm verison 6.14*
Downgrading to npm verison 6.13.7 solved for me
npm i -g npm#6.13.7
It's also an newly opened issue
you can check more details about it at
https://github.com/npm/cli/issues/1185
You just need to run npm i npm#6.13.7 or npm I -g npm#6.13.7 if you wanna this to be global version.
After that, just to make sure, run " npm -version " to see what version you are using.
Downgrading to npm version 6.13.7 worked for me.
Try this:
npm cache clean --force
npm config rm proxy
npm config rm https-proxy
And remove your node_modules within your user.
In Windows, it is
C:\Users\${select_your_user}\AppData\Roaming\npm\node_modules
I was facing the same issue when running npm install on Docker.
I had to pass the HTTP and HTTPS proxy values to the image while building it.
docker build --build-arg HTTP_PROXY=http://<your_company_proxy> --build-arg HTTPS_PROXY=http://<your_company_proxy>
It worked fine after I passed these parameters.
In my case it was the issue related to npm verison 6.14*
Downgrading to npm verison 6.13.7 solved for me
npm i -g npm#6.13.7
It's also an newly opened issue you can check more details about it at https://github.com/npm/cli/issues/1185
it is works for me
Editing the .npmrc file to 80000 works. If not, globally uninstall create-react-app:
"npm uninstall -g create-react-app" then run "npx create-react-app ./"
I recently have the same issue and following steps would help you.
npm config set registry "http://registry.npmjs.org" --global (sets registry) (Try Again)
Go to you user folder find .npmrc file there and remove content of it.
run npm cache clean --force
still errors - Remove the content of npm base folder usually inside User/AppData/roaming/npm/...
I tried everything including factory resetting my Mac. Then after reinstalling everything and still having the same issue, I typed into the terminal and ran:
npm set timeout=100000
then sat my computer next to my router and ran npx create-react-app again and it worked!
Sometimes it won't work if you use only letters in your app name e.g first I have used "myapp" and that was not working though I have done all the other stuffs correctly like set timeout = 240000 in .npmrc file and run the following commands
npm cache clean --force
npm install create-react-app
npx create-react-app myapp
but that not working for me then I have just changed my project name from myapp -> my-app and it worked perfectly. So, If you are facing the same issue try them out. Hopefully, it saves your time.
I tried many things for 3 days, then i figure out that new versions of nodejs doesn't work so fine for some computers, i downgrade to 16.0.0 and then worked
Regarding npx ...
If you have create-react-app (CRA) globally installed;
it is recommend you uninstall CRA
to ensure that npx always uses the latest version.
When using npx, the global installation isn't used.
But it may interfere (addressed below).
Don't run your React app from your desktop.
Some operating systems may throw an error.
Windows OS users ...
As administrator (for steps #1 & #2), inside your command-line ...
1) uninstall your global version of CRA.
npm uninstall -g create-react-app Mac prefix: sudo
2) Then ...
Run: npx create-react-app my-app Mac prefix: sudo
Above: This will create the latest version of
a React app named: my-app.
This app will be created wherever your command-line is pointing.
3) Open Google Chrome.
4) cd my-app (point your command-line to your project folder).
5) inside your command-line ... Run: npm start

Removing old versions of create-react-app

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

'yarn start' throws babel-eslint error MacOS, how do I fix this error?

I am trying to create a React.js App however once created and I try to run using 'yarn start' in the terminal I get this:
yarn run v1.12.3
$ react-scripts start
There might be a problem with the project dependency tree.
It is likely not a bug in Create React App, but something you need to fix locally.
The react-scripts package provided by Create React App requires a dependency:
"babel-eslint": "10.0.1"
Don't try to install it manually: your package manager does it automatically.
However, a different version of babel-eslint was detected higher up in the tree:
/Users/olliesaunderson/node_modules/babel-eslint (version: 9.0.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 "babel-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 /Users/olliesaunderson/node_modules/babel-eslint is outside your project directory.
For example, you might have accidentally installed something in your home folder.
7. Try running npm ls babel-eslint in your project folder.
This will tell you which other package (apart from the expected react-scripts) installed babel-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.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
I have tried following the steps suggested however none of this seems to works. I have also tried yarn add --exact react-scripts#3.0.1 and yarn cache clean
I fixed it!
So as the error shows, there is an existing folder of 'babel-eslint' somewhere higher up in my dependency tree. All I had to do was search in finder for that folder and then delete it, once done you can just 'yarn install' again and 'yarn start' then it should work :)
I have no idea where this other 'babel-eslint' folder came from btw...

"npm start" command suddenly stopped working with "create-react-app" project folders with both old and newly created projects

I've been using create-react-app to make some projects in react and also for practicing, and usually the way to run the project is to use the command npm start from the root directory of that project in the terminal. This has since stopped working for both my old projects which I haven't touched or completely new ones, and followed the exact instructions given by the error already to no effect.
An image of the error, the very top of the terminal is immediately after the npm start command:
I have been googling this over the past two days and I simply can't figure it out. I'm hoping someone with better knowledge would know the root of why npm start has stopped working. Please keep in mind that I already tried the suggestions provided by the error in the terminal.
What's really mind boggling is I haven't changed pcs or done any editing in the old projects such as the one in the picture above, re-installed a bunch of stuff I thought might have been causing issues like npm or babel but they simply don't launch anymore.
Also almost forgot the error log, which has been even more confusing to figure out or google:
You have problem with your dependencies. Please run
npm i
inside project directory.
As your console shows, you can try
remove your node_modules directory
delete file package-lock
I suggest clean npm cache (npm cache clean -f)
and reinstall node_modules using
npm i
There are many reasons to cause this problem.Some suggestions here:
1.uninstall babel-loader and create-react-app globally
npm uninstall -g babel-loader
npm install -g create-react-app
2.remove the error package
rm -rf ~/node_modules/babel-loader
3.stop all the command then clean up the cache of npm

Resources