npm ERR! Unexpected end of JSON input while parsing near ' - node.js

So this error randomly popped up while I was working on my project:
I've searched online and most of the answers ask to run npm cache clean --force.
This did not work for me :(
I've also tried to reinstall npm but still get the same error.
Here is the error-log:
I've been stuck on this for a while hoping someone can help me out :/

You should try to reinstall entirely nodejs from your computer. This could solve the problem.
sudo apt-get remove nodejs
sudo apt-get install nodejs

You can try "yarn" instead of npm.
Installation (If you are using Mac):
brew install yarn
Or check here
https://classic.yarnpkg.com/en/docs/install/
Then just run (Works like "npm install")
yarn

try npm cache clean --force, fixed the issue for me.
ref: npm-err-unexpected-end-of-json-input-while-parsing-near-743

For my Vue.js project this problem was solved by first deleting the package-lock.json file and then running npm install
Comment from #user2864740 helped point me in this direction, thank you!

Related

Create a React app with express, 'react-scripts' error

I have been following this webpage: https://medium.com/walmartglobaltech/creating-react-redux-express-full-stack-application-part-i-82959d847802
So the first time I ran into some issues so I thought it would be best to start from scratch.The first time I kept getting errors about 'react-scripts' is not recognized. I tried 'npm install react-scripts --save' but that didn't work so I gave up and deleted that project.
But when I made the new one it highlighted a bunch of stuff as wrong. And when I got to 'npm start' it keeps saying, 'react-scripts' is not recognized as an internal or external command. My friend did this and she didn't run into this error. I am new to Node.js anything would be helpful!
things that I've tried that didn't work:
npm install -f
rm -rf node_modules && npm install
npm install --save react-scripts
npm cache clean --force
npm rebuild
npm install
I created a new workspace and it inherited the error- is there a way to delete it all and try again?
-Please help
You can try using yarn. There have been some who solved it this way. I hope you can solve your problem.
yarn add react-scripts
So there were two issues: first my directory needed to be updated and I didn't have the node_modules in my client folder - hope this helps anyone else!
I had similar problem, but I restarted the system and it worked. Don't know exactly what was causing this issue might be a cache issue.

node js npm package installation not completed

I try to install node js npm packages, but It start to install and unfortunately freezes. I also try to install angular packages and it doesn't any problem. please help to fix this issue.
node version is 12.13.1;
npm version is 6.12.1;
I tried to install packages this way
npm i html-to-xlsx
here is a result:
another installation result:
Try the following commands then re-run the command:
npm cache clean --force
npm cache verify
And make sure you are in a place with good internet connection. Sometimes this is the issue.
I found way to fix this issue. I add -g before package name
npm install -g html-to-xlsx
Everything looks good
After that I enter this path C:\Users{USERNAME}\AppData\Roaming\npm\node_modules and copy needful module into my working folder

Not able to install #angular/cli using npm

I am new to "#angular/cli", I have tried every thing but could not install.
I am tired now please some one can help me to install angular 4 "#angular/cli" in my system.
node and npm Version
and when I am installing "npm install -g #angular/cli" then getting
after installing node -v 6 I am getting below erorr
please suggest me where actually I am wrong.
My friend,
Please try: npm cache clean --force. Maybe your npm cache got confused.
It could be issue with your node version. I will suggest you to reinstall node and try it again.
Or you can also try to clean node cache of using npm cache clean --force
List of Npm registry
https://registry.npmjs.org/ (Dfault One)
https://r.cnpmjs.org/
https://registry.npm.taobao.org/
https://registry.nodejitsu.com/
https://skimdb.npmjs.com/registry
To switch just type
npm config set registry "https://registry.npmjs.org/"
Replace the registry url with the above urls check which one works for you.
I am from india so i used https://r.cnpmjs.org/ and the same error got resolved.
Note: Please use npm cache clear (To clear cache ) and npm cache verify (To verify its clear or not), This Method works for me
Changing Registry location worked for me .
Using :
npm config set registry "https://registry.npmjs.org/"
few warnings but meh! life's too short for warnings.(Every thing is working fine BTW)
It is possible your npm cache has a corrupted file, perhaps it partially downloaded something and then got an error. Try npm cache clean --force and see if that helps.
If that doesn't help look in the log file given in the error message. Find the unexpected end of JSON input message in the log file and look before it to see if there are any other hints to the problem.
You updated your question with a new error message. That one is more specific about the corrupted file. Try removing the cli-1.5.5.tgz file from the path specified and try again. If you are using a web proxy on your network then it is also possible that your proxy has stored a corrupted cache: if you are able then turn off any proxies configured for your system and try a direct download.
Perhaps you are missing space- npm install -g #angular/cli#latest
1) Install node.js and check and node -v in command prompt. (Node.js
through website).
2) npm install -g #angular/cli#latest (run in command prompt).
Refer this link for further help
https://github.com/angular/angular-cli
3) Check node -version
4) Check npm -version
5) check ng -version
If already installed, then uninstall it and install again,
npm uninstall -g #angular/cli
npm cache clean
Both the CLI and generated project have dependencies that require Node 6.9.0 or higher, together with NPM 3 or higher.
Try using different Node version.
First try updating NodeJS(8.9.3) and npm(5.6.0). These are the LTS versions. For Node this can be important! If that doesn't work, follow this installation guide for windows.
Make sure you are not connected to VPN while installation is on.
Also, please cleanup your node_modules folder before your next try. I use the command rimraf node_modules to remove this directory in windows.
Lastly try running npm install -g #angular/cli#latest
run npm install -g #angular/cli#latest in command prompt as an admin.
right click the windows button, click on command propmt (Admin) or windows power shell(Admin) depending on your windows version. Then type the command and run it.
Most times, you could get issues when you want to install as a normal user considering the fact that you are using the -g (global) flag.
We too have the same kind of issue with user login then we tried from Administrator login its worked for us. Please do the same it may fix for you too.
Please try running:
rm -rf node_modules package-lock.json
And this,
npm install
If it still does not work, try to manually install cli:
npm install --save-dev #angular/cli
When an npm package is published, the publishing process generates a checksum that npm uses at install time to verify that the package didn't get corrupted in transit.
I had the exact same problem, while i was working in a client site, so the problem could be not your environment, they may have a proxy that needs to be configured, in my case we had a nexus server we were going through, and it has something wrong, but when i started using npm registry directly everything worked fine, but most of the time it's a cache problem, to be sure of that you should run:
npm doctor
you will probably find where is the issue.
if not please post the result maybe i can help.
Make sure your console is running as Admin,
Reinstall node & npm
Reinstall angular/cli
Most probable issue is with npm cache. Just clean your npm cache by command
npm cache clean --force
It should work well.
Uninstall your node package. And try the following
Install the latest node package from
https://nodejs.org/en/download/
Check your node and npm version by
node -v
npm -v
Now install the Angular latest version by
npm install -g #angular/cli
Check the angular version by
ng v
Now start creating your application from
https://angular.io/guide/quickstart
So I'm working with Hyperledger which requires you to have a certain Node version 8 and therefore you cannot use the newest angular installation. Perhaps I can recommend another alternative?
cd into the directory
npm install
npm start
You can also clean your npm cache but if one way doesn't work, try the other.
Try navigating to /usr/local/bin and :
if check if the file named ng is present over there, if yes then
rm -r ng and it will remove that file.
Then you can try sudo npm i -g #angular/cli#latest
And it will be a successful install.
(Writing this for those who might also face this issue in future)
Npm cache clean --force
Then install npm
Then go for angular
Npm I -g #angular/cli
was having a similar issue while installing angular cli using npm.
this was resolved by running:
npm cache clean --force
It happened to me once, looked like I had to specify the version of angular cli:
https://github.com/angular/angular-cli/issues/11589
e.g.:
npm install -g #angular/cli#1.5.0
It could be issue with your node version. I will suggest you to reinstall node and try it again.
Or you can also try to clean node cache of using npm cache clean --force
Please check this also Perhaps you are missing space- npm install -g #angular/cli#latest

Can install but can't run npm packages

I'm having trouble with my node.js/npm setup,
I freshly installed it via the website and it worked fine.
It told me to make sure /usr/local/bin/npm has to be in my path and when I run
echo $PATH it is in there, so it should be fine.
I can now install packages (tested with npm i webpack -save-dev) the installation works as expected, without any errors.
But when i run webpack all It is giving back is command not found has anyone experienced
something like this before?
I believe what you are looking for is a global package install.
Try using
npm i -g webpack
You can get help on install with
npm help i
Did you install node v8/npm v5?
In that case, it seems there's an open big-bug ticket on the npm repository.

NPM not working. Cannot find module 'strip ansi'

I just downloaded node but npm is not working. whenever I use a npm comman I get Error: cannot find module 'strip-ansi'.
For what it's worth, this ended up happening to me, using nvm on mac. npm cache clean didn't work. I ended up reinstalling via nvm:
$ curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bash
$ nvm install node
I was stuck on this problem too. Finally, I solved the issue by adding value '.js', '.ts' to resolve.extensions in my webpack.config.js. If you are using webpack too, this may help.
just reinstall strip using npm install strip --save this kind of error occurs because some file may be corrupt in strip library if this will not work you can try also npm install you will solve this error.
I hit this same issue. I tried to update npm after a fresh Node.js install, but cancelled in the middle because it appeared stuck. Reinstalling Node.js didn't help.
I resolved the issue by deleting the temporary npm files in my AppData folder (for me on Windows, I found it in c:\Users\Me\AppData\Roaming\npm). Then I was able to run npm normally again.
Hope that helps!
It solved for me by going to the NPM install folder at /usr/local/lib/node_modules/npm and running the yarn command. After running it successfully, NPM started working normally.
I had the same issue with my next js application. What i did was uninstall strip-ansi(npm uninstall strip-ansi) and then reinstall (npm install strip-ansi)
Clear your temporary paths of npm and this is solution.
if you're using linux:
go to $ cd /tmp/
search by npm-* folders
and remove all.
Solved by doing npm cache clean and then npm install

Resources