node-pre-gyp: npm@5 TypeError: Cannot read property 'version' of null

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:

About this issue

  • Original URL
  • State: open
  • Created 7 years ago
  • Reactions: 63
  • Comments: 16 (2 by maintainers)

Commits related to this issue

Most upvoted comments

workaround: Remove the lock file.

rm .\package-lock.json

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

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

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

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.

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.

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

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.