What does 'invalid' mean when using npm list? - node.js

I am new to nodejs and i had just installed bower module globally. Ever since then, npm list command gives the following output which I searched for on the web but couldn't find any help :
**npm ERR! invalid: chalk#0.5.1 /usr/local/lib/node_modules/bower/node_modules/chalk
npm ERR! invalid: ansi-regex#0.2.1 /usr/local/lib/node_modules/bower/node_modules/chalk/node_modules/has-ansi/node_modules/ansi-regex
npm ERR! invalid: configstore#0.3.1 /usr/local/lib/node_modules/bower/node_modules/update-notifier/node_modules/configstore
npm ERR! invalid: object-assign#0.3.1 /usr/local/lib/node_modules/bower/node_modules/update-notifier/node_modules/latest-version/node_modules/package-json/node_modules/got/node_modules/object-assign
npm ERR! invalid: registry-url#0.1.1 /usr/local/lib/node_modules/bower/node_modules/update-notifier/node_modules/latest-version/node_modules/package-json/node_modules/registry-url
npm ERR! invalid: strip-ansi#0.2.2 /usr/local/lib/node_modules/bower/node_modules/update-notifier/node_modules/string-length/node_modules/strip-ansi
npm ERR! not ok code 0**
The rest of the output is normal and lists the installed modules. Can anyone explain what's going on?

I was getting this error having the same package installed both in "dependencies" and "devDependencies" with different versions.

It means that something depends on, for example, "async":"0.9.3" but when they do require("async"), npm thinks that they'll get some other version. And also check that the dependencies and their versions listed in your package.json file are available.
If everything is right then you can solve this problem with
npm update
followed by
npm install.

I was getting this error after installing a newer version of a module, without updating my package.json. So the package.json required the older version, while npm list was detecting a newer version in my node_modules directory.
Running the following command got me rid of the message.
npm install {required_module}#{new_version} --save

Simplest answer
This can arise when the installed version of a package does not correspond to what package.json would install.
Example
Say you have specified "axios": "0.19.2", in your package.json, but after that you would install a specific version using npm install axios#0.18.1.
An npm list | grep axios would now yield
├─┬ axios#0.18.1 invalid
Follow the instructions in this answer on how to fix it.

I was getting a related but different error (but ended up here, so I'm answering here) where after running npm update I'd get. (No such issue with npm install, fwiw)
myapp#1.0.0 /home/malcolm/myapp
├── beeminder#1.4.3 invalid
The beeminder package is one I maintain, so in my main app I had set its semver to latest. This seemed to work fine before, but I guess a newer version of npm doesn't like it.
I figured it was reasonable to just use ^1.4.3 because if I'm introducing new changes then I probably am changing my own code anyway. But if for some weird reason you need the latest latest of a package (including breaking changes!) then you can use >= as a prefix instead of ^.

Related

npm ERR! must provide string spec

I'm having this error since a while, in this case, the problem occur executing the following command.
npx create-react-app my-app
Actually, it happens with any npm commands as well, I tried deleting package.json, changing npm versions and yet didn't work, so I'm here asking for help.
This is the entire error:
C:\Users\c>npm install
npm ERR! must provide string spec
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\c\AppData\Local\npm-cache\_logs\2022-01-28T16_50_23_009Z-debug.log
Version of npm and node:
node --version
v16.13.2
npm --version
8.3.2
I had the same issue, it was a missing version in my package.json
look like mistakenly I removed some text
"dependencies":{
"angular/cli" :"{}"
}
try to update your npm: npm upgrade
then: npm clean cache
Following, i'm in the exact same position. Tried changing the NodeJS version using NVM and now some of the commands work (npm -v shows im running 8.1.0) but npm update and npm/npx create-react-app give me an " ERR! must provide string spec " !
I faced this same issue yesterday.
This is what I did to resolve it:
Uninstalling node entirely and removing node_modules and package.lock.json from the project directory.
Install node afresh and run npm install in your project directory.
I tried to reactivate an old project which had packages noted down differently then usual in package.json. They had an id and locator parameter, like:
"ImagePicker": {
"id": "ImagePicker",
"locator": "https://github.com/dhavalsoni2001/ImagePicker.git"
}
After removing / replacing them by version numbes, i could install.

On 'npm outdated' error: Only tag, version, and range are supported

There are "named" references in my package.json (npm 7.20.3)
"bootstrap-legacy": "npm:bootstrap#4.6.0",
"sass-legacy": "npm:sass#1.32.13",
But after this npm outdated stop working:
npm ERR! Only tag, version, and range are supported npm ERR! A
complete log of this run can be found in: npm ERR!
..\npm-cache_logs\2021-09-09T09_14_26_242Z-debug.log
Nothing interesting in the log
Do we have any workaround for this? Any key for the outdated command ? Other command to list outdated packages? Solved in later npm versions?
P.S. npm install works well.
there is an open issue on github which you can follow and like in order to get it fixed. There seems not to be a general solution to the alias issue, but in some cases the usage of aliases can be avoided.

Why am I getting Unexpected token '\u0000' when using npm install -g package

This is probably a Windows specific issue but I haven't found any information when googling this issue. I had been using ionic framework which relies on Cordova (or Phonegap). However, the problem is not specific to any of these packages. I see this error quite often. So, the error is when I run a command such as the following:
npm install -g cordova
However, I could substitute various other packages and get the same error. I'll paste the snippet (very brief) below of the error message. What is strange is that I had an ionic project working in that directory earlier. Then today it told me that ionic could not be found. My hunch is that this is a different issue than the main issue I am describing here.
I installed git bash so I do have a linux-like environment that I could try. I would just select Git Bash for a bash window with various bash commands. If there is an easier way to fix this for Windows users, please let me know. I have seen courses on Pluralsight where the instructors seem to be happily using npm with no problems. Also, when I use yeoman, I also at some point, in many cases, get the same error.
The error is
npm ERR! Failed to parse json
npm Unexpected token '\u0000' at 1:1
npm ERR!
npm ERR! ^
npm ERR! File: c:\Users\Bruce\AppData\Roaming\npm-cache\amdefine\1.0.0\package\package.json
npm ERR! Failed to parse package.json data.
npm ERR! package.json must be actual JSON, not just JavaScript.
npm ERR!
npm ERR! This is not a bug in npm
npm ERR! Tell the package author to fix their package.json file. JSON.parse.
Thanks in advance for any help/advice,
Bruce
Via this question on SO it could be that you just have to do:
npm cache clean.
But, also try the other methods suggested there like adding the registry option:
npm install <packagename> --registry http://registry.npmjs.org/.
Or, if you've been mingling with the package.json file by yourself, check if it's valid.

Why does npm list -g lead to npm ERR! missing error?

npm returns the following message after using npm list -g
npm ERR! missing: atom-package-manager#*, required by undefined#undefined
npm ERR! missing: opal-npm-wrapper#git://github.com/anthonny/opal-npm-wrapper.git#0.1.1, required by asciidoctor.js#1.5.2
npm ERR! missing: xmlhttprequest#~1.6.0, required by asciidoctor.js#1.5.2
screenshot:
I know this an old question but I've been strugging with a similar issue and figure I'd at least add what worked for me...
Problem
Running npm list -g lists all packages as expected and then throws a variety of errors including the missing errors, as mentioned above, and, for me at least, a bunch of invalid and extraneous errors such as this:
extraneous: aws-sign2#0.5.0 /usr/local/lib/node_modules/npm/node_modules/aws-sign2
I tried a bunch of solutions including npm upgrade, npm prune, as well as installing missing packages, which for me was semver:
missing: semver#2 || 3, required by normalize-package-data#1.0.1
I'm still not sure of the exact cause for these errors, though I believe this happened when I upgraded to 3.3.6.
Solution
After some headache I ran:
npm update -g --verbose
which upgraded me from v3.3.6 to v3.5.3 and got rid of all the errors. Note that the --verbose is not necessary but helpful to see what exactly is happening. Now my npm list -g returns a clean output:
/usr/local/lib
├── npm#3.5.3
└── semver#2.3.2
Hope this helps someone, please comment if I've stated any inaccuracies or if there's something I can add here.
For anyone having the same problem, try to run:
npm dedupe
for more info about npm dedupe please refer to the documentation.
https://docs.npmjs.com/cli/dedupe.html
Remove package-lock.json in /usr/local/lib.
You must have a global package named asciidoctor.js that is installed before its dependency packages are installed. I ran into the same problem today: some of my global package has "UNMET DEP" in its tree structure(run npm list -g to see the full depth of each global package), meaning its subdependencies are missing.
I solved by reinstalling each global package. If you had this problem on Arch Linux,
first check this post: I have unmet dependencies
I had this problem surfaced after I sudo pacman -Syu and I have a bunch of ERROR missing semver and node-pyg.
As a side note, under Arch Linux node-pyg and semver are installed as dependencies before npm is installed through pacman(rather than through npm), and I guess the order these two are installed or updated matters. Probably under other OS or linux distros, these two packages are not listed in the repository.

How to override a npm install version check failure?

Is there a way to override npm's version checking against a packages.json file from command line (npm install command)?
I would like to try and install/run a package even though it doesn't match my node.js version.
This is the error I am getting:
npm ERR! Unsupported
npm ERR! Not compatible with your version of node/npm: canvas#0.6.0
npm ERR! Required: {"node":"0.4.x"}
npm ERR! Actual: {"npm":"1.0.8","node":"v0.5.0-pre"}
Thanks
What you could do is go to github package and update the package.json. Then just install it locally. But most of the times these version numbers are there for a reason. The node.js api changes sometimes(I believe 0.5.0-pre changed, because socket.io also fails with 0.5.0-pre).
If you for example install nvm, nave you can keep several version of node.js side-by-side easily.
If all else fails you could still manually download and copy the files in your node_modules folder

Resources