How to override a npm install version check failure? - node.js

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

Related

How do you fix and error of an Invalid version of NPM for installing #nestjs/core?

Hey so i just recently started learning Nestjs and I was asked to setup the environment on my Chromebook(Linux terminal). All packages have been successfully installed except a package #nesjs/core. I've tried running the command to install the package npm install #nestjs/core but anytime i run the command it keeps giving me this error:
npm ERR! Invalid Version:
npm ERR! A complete log of this run can be found in:
npm ERR! /home/jefferson/.npm/_logs/2022-07-09T07_13_30_344Z-debug-0.log
So far I've tried changing my version of npm to version 6.2.0, deleting and reinstalling nodejs and npm but there's been no positive result.
Please what else should I try doing
If your Node version is very recent, try downgrading. Stable version 14.16.1 worked.

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.

NPM stuck on an old version?

I was following some tutorial that was recorded a while ago, and it said for us to downgrade our npm version to 5.5.1 to avoid any differences (since that was the newest version at the time of the recording). So I did, using classic
npm install -g npm#5.5.1
However, now I'm stuck, I can't update to the actual present day latest version. I tried npm install -g npm#latest, I tried manually typing the latest version, I even tried uninstalling both Node and NPM, and installing the latest ones, fresh from the site, but for whatever reason my npm just gets stuck on 5.5.1 again. How do I fix this?
I'm using Windows btw. Also, I'm just learning about Node and NPM, so I guess there is a chance I'm missing some obvious solution?
Edit: whenever I try to install something, I get the following
npm WARN npm npm does not support Node.js v12.18.3
npm WARN npm You should probably upgrade to a newer version of node as we
npm WARN npm can't make any promises that npm will work with this version.
npm WARN npm Supported releases of Node.js are the latest release of 4, 6,
npm WARN npm You can find the latest version at https://nodejs.org/
WARNING: You are likely using a version of node-tar or npm that is incompa
with this version of Node.js.
Please use either the version of npm that is bundled with Node.js, or a ve
of npm (> 5.5.1 or < 5.4.0) or node-tar (> 4.0.1) that is compatible with
s 9 and above.
and after that a long list of errors, including, but not limited to
1: 000000013F8A5EBF napi_wrap+114095
2: 000000013F850B46 v8::base::CPU::has_sse+66998
3: 000000013F850EC1 v8::base::CPU::has_sse+67889
4: 000000013F78F187 RSA_meth_get_flags+85639
5: 000000014001AAE0 v8::internal::Builtins::builtin_handle+323456
try this
Run PowerShell as Administrator
Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force
npm install -g npm-windows-upgrade
npm-windows-upgrade
refer to this https://www.npmjs.com/package/npm-windows-upgrade or their GitHub repo for more help
if it doesn't help, try this
uninstall node (Settings -> Add or remove programs), then navigate to C:\Users\{User}\AppData\Roaming and delete the npm and npm-cache folder and finally install node again (using the installer).
You are missing the -g. You said:
I tried npm install npm#latest
but that that doesn't include the -g. The -g is key because it causes npm to be installed globally (best rhyme). See Downloading and installing packages globally. Your first command includes it, but not the follow up.
Because of this, you probably install npm as a local dependency (which you probably didn't mean to do). Check your package.json and see if there is any listing of npm. If you aren't directly using runtime pieces of npm, remove that dependency and just install the specific version you want globally with -g.
In your project root directory, run the update command:
npm update

What does 'invalid' mean when using npm list?

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 ^.

NodeJS npm - Using Contextify on windows

I'm able to build contextify 0.1.1 using node-gyp on Windows, but I don't know how to get npm to recognize/use this version when resolving other modules' dependencies. 'npm install' fails with the same (expected) 'node-waf was unexpected at this time.' error, despite having a build version of contextify in the local directory.
Put simply: how do I tell npm to use a module I've built myself, instead of trying to download/build its own?
npm install installs modules into the current directory's node_modules directory. So instead of using npm install at all, just move/copy the contextify module that you built yourself to node_modules/contextify. Unfortunately you will have to do this for any module that depends on contextify.
Hope that helps!

Resources