TypeError: Cannot read property 'length' of undefined in file semver/semver.js:239:14
when I run it - parameter "version" === undefined
Error: gyp info it worked if it ends with ok
gyp info using [email protected]
gyp info using [email protected] | linux | x64
gyp ERR! UNCAUGHT EXCEPTION
gyp ERR! stack TypeError: Cannot read property 'length' of undefined
gyp ERR! stack at parse (/home/alexander/www/electron/project-name/node_modules/semver/semver.js:239:14)
gyp ERR! stack at Function.valid (/home/alexander/www/electron/project-name/node_modules/semver/semver.js:255:11)
gyp ERR! stack at processRelease (/home/alexander/www/electron/project-name/node_modules/node-gyp/lib/process-release.js:16:25)
gyp ERR! stack at configure (/home/alexander/www/electron/project-name/node_modules/node-gyp/lib/configure.js:35:17)
gyp ERR! stack at Object.self.commands.(anonymous function) [as configure] (/home/alexander/www/electron/project-name/node_modules/node-gyp/lib/node-gyp.js:55:37)
gyp ERR! stack at run (/home/alexander/www/electron/project-name/node_modules/node-gyp/bin/node-gyp.js:87:30)
gyp ERR! stack at _combinedTickCallback (internal/process/next_tick.js:67:7)
gyp ERR! stack at process._tickCallback (internal/process/next_tick.js:98:9)
For fix it I just add code above into function function parse(version, loose) {
if(version === undefined) {
return null;
}
Is there an easy way for me to reproduce?
Can you print the output of node -p process.versions and check what that "version" field in /home/alexander/www/electron/project-name/node_modules/semver/package.json says?
Is there a reason you have node-gyp in your node_modules directory instead of using the one that is bundled with node/npm?
I'm encountering the same issue, and have come across this before. Last time I found that removing a particular package, which didn't require node-gyp compilation, fixed it for some reason. I had to find this package by trial and error, which takes a while with a large application.
node -p process.versions
{ http_parser: '2.7.0',
node: '7.5.0',
v8: '5.4.500.48',
uv: '1.10.2',
zlib: '1.2.8',
ares: '1.10.1-DEV',
modules: '51',
openssl: '1.0.2k',
icu: '58.2',
unicode: '9.0',
cldr: '30.0.3',
tz: '2016j' }
Adding the if (version === undefined) { return null; } makes everything work correctly. I've traced it back to a 'todo' with content [ { name: 'configure', args: [] } ]. It looks like args[0] should contain a semver number, but it doesn't - causing the error later on.
I'm using electron-builder, which is calling node-gyp, so for me the error may be coming from there - but it might be worth adding some kind of check that gives a nicer error message when this happens.
The newer versions of semver include the undefined check by default. I think the behavior I was encountering was down to the way npm resolves modules. If I included a module that had an earlier version of semver as a dependency, node would use that version instead (as node-gyp is happy with semver versions from 2 to 5) which caused the error to occur. The simple fix is to explicitly require semver 5 which will override anything else.
npm install --save [email protected]
For reproducing the issue, try passing [ { name: 'configure', args: [] } ] with semver 4.
I think we can upgrade to a newer semver in node-gyp. We specified a broad range so we could share it with npm but since npm upgraded their dependency recently, we can too now.
https://github.com/nodejs/node-gyp/pull/1107