package.json with wrong version


(Gustavo Paes) #1

What I Wanted to Do

I want to run npm install in a project with wrong value at version attribute and get a fail exit (exit > 0).

What Happened Instead

No one dependencies are installed and the script exists with success code (exit 0).

Reproduction Steps

  1. Create a package.json with wrong version attribute (ie: just two numbers):
{
  "name": "awesome-app",
  "version": "1.0",
  "description": "Just a bug demonstration",
  "main": "index.js",
  "scripts": {
    "start": "node index.js"
  },
  "dependencies": {
    "dotenv": "^6.1.0"
  }
}
  1. Run npm install
npm i
npm WARN Invalid version: "1.0"
  1. Get script exit code: echo $?
echo $?
0
  1. No one dependency was installed:
ls node_modules
ls: cannot access 'node_modules': No such file or directory

Platform Info

$ npm --versions

{ npm: '6.4.1',
  ares: '1.14.0',
  cldr: '33.1',
  http_parser: '2.8.0',
  icu: '62.1',
  modules: '64',
  napi: '3',
  nghttp2: '1.34.0',
  node: '10.13.0',
  openssl: '1.1.0i',
  tz: '2018e',
  unicode: '11.0',
  uv: '1.23.2',
  v8: '6.8.275.32-node.36',
  zlib: '1.2.11' }

$ node -p process.platform
linux