Reputation:
I'm using npm install and validate the package JSON content is valid and I'm getting the following error:
After reading on the web, I did "rm -f package-lock.json && npm install"
(even if I didn’t see any package lock there) and did also npm cache clean -f
which doesn’t help, also configured registry.
See Can't install any package with node npm
I'm using the latest npm, 6.2.0.
The error in the logs is:
159 silly saveTree ├── [email protected]
159 silly saveTree ├── [email protected]
159 silly saveTree └── [email protected]
160 verbose stack SyntaxError: Unexpected token < in JSON at position 0 while parsing near '<html>
160 verbose stack <head><title>...'
160 verbose stack at JSON.parse (<anonymous>)
160 verbose stack at parseJson (/usr/local/lib/node_modules/npm/node_modules/json-parse-better-errors/index.js:7:17)
160 verbose stack at consumeBody.call.then.buffer (/usr/local/lib/node_modules/npm/node_modules/node-fetch-npm/src/body.js:96:50)
160 verbose stack at <anonymous>
160 verbose stack at process._tickCallback (internal/process/next_tick.js:188:7)
Is there is something else I can do?
Upvotes: 13
Views: 39471
Reputation: 1
I had a similar issue on one of our repos. In our case the package.json
file was encoded as UTF-8-BOM
instead of UTF-8
, and the JSON data in the file could not be parsed.
Upvotes: 0
Reputation: 57
I came across this issue, as well.
This solution in Can't install any package with node npm helps me.
The command is below:
npm install <packagename> --registry http://registry.npmjs.org/
But, this is painful. After a while, I found that I set the wrong registry mirror.
npm config ls -l
Then I found the value is http://www.npmjs.org/
npm config set registry https://registry.npmjs.org/
After that, I solved it!
Upvotes: 0
Reputation: 364
I got the same error in NestJS and I found out that the error was in nest-cli.json and not in any other file.
Upvotes: 0
Reputation: 766
For people who have removed node_modules
and facing error after npm install
.
This can also be a problem if you have a preinstall script under package.json
like this:
"scripts": {
"preinstall": "npx npm-force-resolutions",
....
Since npm-force-resolutions
looks for node_modules to resolve. To fix it, just comment the preinstall script, run npm install
and then revert the comment and run npm install
again just to keep things verified.
Upvotes: 0
Reputation: 474
Deleting Node Modules and package-lock JSON file, solves this issue in many cases.
These are the steps to be followed:
Delete the node_modules
folder.
Delete package-lock.json
file.
Verify the cache
Run npm install
again.
Let's use rimraf
Install rimraf globally
npm install rimraf -g
Remove node modules
rm -rf node_modules
Remove package-lock.json
rimraf package-lock.json
Verify cache
npm cache verify
Install the modules again
npm install
Upvotes: 0
Reputation: 6692
Your package.json, or maybe other JSON file is incorrect. You must first fix JSON errors.
Upvotes: 4
Reputation: 932
This worked for me:
rm -rf node_modules
rm package-lock.json
npm cache verify
npm install
Upvotes: 4
Reputation: 5848
Do the following:
Delete the node_modules
folder.
Delete package-lock.json
file.
Run npm install
again.
Upvotes: 12