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

TypeError: Cannot read property 'length' of undefined in file semver/semver.js:239:14 #1094

Closed
AleksandrChernyavenko opened this issue Jan 23, 2017 · 5 comments · Fixed by #1107

Comments

@AleksandrChernyavenko
Copy link

when I run it - parameter "version" === undefined


Error: gyp info it worked if it ends with ok
gyp info using node-gyp@3.5.0
gyp info using node@6.9.4 | 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;
  }
@bnoordhuis
Copy link
Member

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?

@TimHollies
Copy link

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.

@TimHollies
Copy link

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 semver@5.3.0

For reproducing the issue, try passing [ { name: 'configure', args: [] } ] with semver 4.

@bnoordhuis
Copy link
Member

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.

@bnoordhuis
Copy link
Member

#1107

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

Successfully merging a pull request may close this issue.

3 participants