Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

npm install fails "invalid version"

Tags:

npm

When trying to install from the package.json, following error occurs

>npm install
npm ERR! install Couldn't read dependencies
npm ERR! Error: Invalid version: "1.0.0.0"
package.json
{
  "name": "version-sample",
  "version": "1.0.0.0",
  "dependencies": { 
      "sample" : "*" 
   }
}
like image 924
MemLeak Avatar asked Dec 18 '14 09:12

MemLeak


People also ask

Why I Cannot install npm?

You need to make sure you have a package. json file right in the current directory where you run the command. Once you see there's a package. json file in the output as shown above, then you can run the npm install command.

How do I change npm version?

You can downgrade the npm version by specifying a version in the related commands. If you want to downgrade npm to a specific version, you can use the following command: npm install -g npm@[version.

How do I install a specific version?

For npm install specific version, use npm install [package-name]@[version-number]. Use npm view [package-name] version to know the specific latest version of a package available on the npm registry. Use npm list [package-name] to know the specific latest version of an installed package.

What to do when NPM fails to install a package?

Check npm's proxy configuration. Check that it's not a problem with a package you're trying to install (e.g. invalid package.json). Many ENOENT / ENOTEMPTY errors in output. npm is written to use resources efficiently on install, and part of this is that it tries to do as many things concurrently as is practical.

What does NPM install--production mean?

By default, npm install will install all modules listed as dependencies in package.json. With the --production flag (or when the NODE_ENV environment variable is set to production ), npm will not install modules listed in devDependencies.

What is NPM alias install?

npm install <alias>@npm:<name>: Install a package under a custom alias. Allows multiple versions of a same-name package side-by-side, more convenient import names for packages with otherwise long ones and using git forks replacements or forked npm packages as replacements.

What is the difference between NPM install and global install?

npm install (in package directory, no arguments): Install the dependencies in the local node_modules folder. In global mode (ie, with -g or --global appended to the command), it installs the current package context (ie, the current working directory) as a global package. By default, npm install will install all modules listed as dependencies in ...


3 Answers

the version number can only be like \d+\.\d+\.\d+ so \d+\.\d+.\d+.\d+ is not valid. so "1.0.0.0" is not valid and and "1.0.0" is. But check the link below for a more accurat description. This works:

package.json
{
  "name": "version-sample",
  "version": "1.0.0",
  "dependencies": { 
      "sample" : "*" 
   }
}

The full documentation is located here https://semver.org/ (including a proper regex

like image 196
MemLeak Avatar answered Oct 17 '22 01:10

MemLeak


"1.0" is not a valid version as defined by Semantic Versioning. Changing it to "1.0.0" should solve your issue.enter image description here

like image 35
user1089766 Avatar answered Oct 17 '22 01:10

user1089766


Try this

  • Delete the npm_modules folder
  • Delete package.json.lock file
  • run npm cache clean --force

And try installing again using npm install

like image 4
Abraham Avatar answered Oct 17 '22 00:10

Abraham