Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

npm@5 TypeError: Cannot read property 'version' of null #298

Open
yvele opened this issue Jun 1, 2017 · 16 comments
Open

npm@5 TypeError: Cannot read property 'version' of null #298

yvele opened this issue Jun 1, 2017 · 16 comments

Comments

@yvele
Copy link

yvele commented Jun 1, 2017

Looks like using npm 5 we have a problem.

package_json.version at line 262 is undefined and throws at line 270

TypeError: Cannot read property 'version' of null
    at Object.module.exports.evaluate (/Users/yvele/repo/node_modules/fsevents/node_modules/node-pre-gyp/lib/util/versioning.js:270:32)
    at install (/Users/yvele/repo/node_modules/fsevents/node_modules/node-pre-gyp/lib/install.js:168:31)
    at Object.self.commands.(anonymous function) [as install] (/Users/yvele/repo/node_modules/fsevents/node_modules/node-pre-gyp/lib/node-pre-gyp.js:50:37)
    at run (/Users/yvele/repo/node_modules/fsevents/node_modules/node-pre-gyp/bin/node-pre-gyp:79:30)
    at Object.<anonymous> (/Users/yvele/repo/node_modules/fsevents/node_modules/node-pre-gyp/bin/node-pre-gyp:131:1)
    at Module._compile (module.js:556:32)
    at Object.Module._extensions..js (module.js:565:10)
    at Module.load (module.js:473:32)
    at tryModuleLoad (module.js:432:12)
    at Function.Module._load (module.js:424:3)

Main NPM issue:

Related issues:

@sgtcoolguy
Copy link

sgtcoolguy commented Jun 2, 2017

I think this is due to npm5 using a URL value for the version property in package.json files now.

There's a hint in the full error output below:

> node-ios-device@1.3.1 install /Users/cwilliams/repos/titanium_mobile/node_modules/node-ios-device
> node-pre-gyp install --fallback-to-build

node-pre-gyp info it worked if it ends with ok
node-pre-gyp verb cli [ '/Users/cwilliams/.nvm/versions/node/v6.10.2/bin/node',
node-pre-gyp verb cli   '/Users/cwilliams/repos/titanium_mobile/node_modules/node-ios-device/node_modules/.bin/node-pre-gyp',
node-pre-gyp verb cli   'install',
node-pre-gyp verb cli   '--fallback-to-build' ]
node-pre-gyp info using node-pre-gyp@https://registry.npmjs.org/node-pre-gyp/-/node-pre-gyp-0.6.34.tgz
node-pre-gyp info using node@6.10.2 | darwin | x64
node-pre-gyp verb command install []
node-pre-gyp ERR! install error 
node-pre-gyp ERR! stack TypeError: Cannot read property 'version' of null
node-pre-gyp ERR! stack     at Object.module.exports.evaluate (/Users/cwilliams/repos/titanium_mobile/node_modules/node-ios-device/node_modules/node-pre-gyp/lib/util/versioning.js:270:32)
node-pre-gyp ERR! stack     at install (/Users/cwilliams/repos/titanium_mobile/node_modules/node-ios-device/node_modules/node-pre-gyp/lib/install.js:168:31)
node-pre-gyp ERR! stack     at Object.self.commands.(anonymous function) [as install] (/Users/cwilliams/repos/titanium_mobile/node_modules/node-ios-device/node_modules/node-pre-gyp/lib/node-pre-gyp.js:50:37)
node-pre-gyp ERR! stack     at run (/Users/cwilliams/repos/titanium_mobile/node_modules/node-ios-device/node_modules/node-pre-gyp/bin/node-pre-gyp:79:30)
node-pre-gyp ERR! stack     at Object.<anonymous> (/Users/cwilliams/repos/titanium_mobile/node_modules/node-ios-device/node_modules/node-pre-gyp/bin/node-pre-gyp:131:1)
node-pre-gyp ERR! stack     at Module._compile (module.js:570:32)
node-pre-gyp ERR! stack     at Object.Module._extensions..js (module.js:579:10)
node-pre-gyp ERR! stack     at Module.load (module.js:487:32)
node-pre-gyp ERR! stack     at tryModuleLoad (module.js:446:12)
node-pre-gyp ERR! stack     at Function.Module._load (module.js:438:3)
node-pre-gyp ERR! System Darwin 16.7.0
node-pre-gyp ERR! command "/Users/cwilliams/.nvm/versions/node/v6.10.2/bin/node" "/Users/cwilliams/repos/titanium_mobile/node_modules/node-ios-device/node_modules/.bin/node-pre-gyp" "install" "--fallback-to-build"
node-pre-gyp ERR! cwd /Users/cwilliams/repos/titanium_mobile/node_modules/node-ios-device
node-pre-gyp ERR! node -v v6.10.2
node-pre-gyp ERR! node-pre-gyp -v vhttps://registry.npmjs.org/node-pre-gyp/-/node-pre-gyp-0.6.34.tgz
node-pre-gyp ERR! not ok 
Cannot read property 'version' of null

Specifically, you see: node-pre-gyp ERR! node-pre-gyp -v vhttps://registry.npmjs.org/node-pre-gyp/-/node-pre-gyp-0.6.34.tgz

Looking at the package.json files in my node_modules folder after an npm5 install, I see things like:

{
  "version": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz"
}

So semver.parse is returning null because these aren't really semantic versioning strings, but urls of resolved packages.
Ultimately I'm not sure if this is a node-pre-gyp "bug" that you'd need to add a workaround for, or it's an npm5 bug. Certainly feels more like an npm bug to me, but then maybe they need/intend for the version value to be a URL for the future.

@springmeyer
Copy link
Contributor

Thanks for the report and digging everyone. As the current maintainer of node-pre-gyp my preference here is to:

@floriantraber
Copy link

workaround: Remove the lock file.

rm .\package-lock.json

@Alexis-Bize
Copy link

Worked for me, thanks @floriantraber!

@mattbell87
Copy link

@floriantraber Thanks!

@dhniels
Copy link

dhniels commented Jun 5, 2017

If you remove the lock file doesnt it just regenerate it again after running npm install?

@borislemke
Copy link

in my case the package-lock.json file got included in the project's commit. When cloning the repo on another machine and doing npm i, this error would be thrown. We added the lock file to .gitignore and all works well.

@alexjlockwood
Copy link

@borislemke That may work as a temporary solution, but the package-lock.json file is meant to be committed to source control.

@maifs
Copy link

maifs commented Jun 10, 2017

I am facing the same issue .
what do i need to fix it ?
Kindly guide. thank you.

https://stackoverflow.com/questions/44462901/how-to-install-latest-angular-cli-using-visual-studio-2017-node-js-interactive-w

@sergioviniciuss
Copy link

Same issue in here..

@alexjlockwood
Copy link

I added package-lock=false to the .npmrc file in my repo's root directory in order to temporarily workaround the issue. Seemed cleaner than adding it to the .gitignore. :P

@dustintheweb
Copy link

@alexjlockwood worked like a champ

@lmuzquiz
Copy link

lmuzquiz commented Sep 5, 2017

I was dealing with this errors many hours until i deleted my package-lock.json file and then ran npm install again. I know the file is re-generated with each npm install but i dont get the node pre gyp errors anymore. So go figure...
Thanks to all of you.

@springmeyer
Copy link
Contributor

springmeyer commented Sep 7, 2017

In addition to removing package-lock.json I've found another workaround.

I was able to replicate this on OS X with:

  • node v8.4.0
  • npm 5.3.0

this package.json:

{
  "name": "master",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "dependencies": {
    "sqlite3": "https://github.com/mapbox/node-sqlite3/tarball/d18c1e97de9478aab27067638899b068e6d8ed03"
  },
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC"
}

And by seeding the node_modules/node-pre-gyp folder with node-pre-gyp@0.6.36.

It seems that something about the install noticing node-pre-gyp already in the node_modules (which is okay and often the case) triggers this odd behavior in npm.

Locally I've been able to solve by doing:

{
  "name": "master",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "dependencies": {
    "sqlite3": "https://github.com/mapbox/node-sqlite3/tarball/master"
  },
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC"
}

Which includes TryGhost/node-sqlite3@34e1a40. So, my hunch is that npm ls is involved here somehow.

refs https://gist.github.com/springmeyer/96f9b937d2ecf71f8b3dc3c58b92be9b

@zouhairkhallaf
Copy link

Thank you @floriantraber for pointing out the removal of package-lock.json. I did that and was still getting the error, but when I removed my node_modules folder and then ran npm install again, It worked. So remove both package-lock.json and node_module folder and ran npm install and that should work.

@skylarmb
Copy link

skylarmb commented Oct 30, 2017

I fixed this by updating to fsevents@1.1.2 which fixes this: fsevents/fsevents#172

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests