Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ng serve erroring after NPM 5.0.1 update: Invalid Version:

Tags:

npm

angular

I just updated to NPM 5.0.1 and right away I had compilation errors in my Angular 4.1.3 project. After deleting and completely reinstalling my node_modules (all packages up to date) I get a strange and red colored error when running ng serve:

Invalid Version: https://registry.npmjs.org/@angular/core/-/core-4.1.3.tgz
TypeError: Invalid Version: https://registry.npmjs.org/@angular/core/-/core-4.1.3.tgz
    at new SemVer (/Users/bracicot/dev/recruitler/node_modules/semver/semver.js:293:11)
    at new Version (/Users/bracicot/dev/recruitler/node_modules/@angular/cli/upgrade/version.js:23:36)
    at Function.assertAngularVersionIs2_3_1OrHigher (/Users/bracicot/dev/recruitler/node_modules/@angular/cli/upgrade/version.js:80:23)
    at Class.run (/Users/bracicot/dev/recruitler/node_modules/@angular/cli/commands/serve.js:102:27)
    at Class.Command.validateAndRun (/Users/bracicot/dev/recruitler/node_modules/@angular/cli/ember-cli/lib/models/command.js:128:15)
    at /Users/bracicot/dev/recruitler/node_modules/@angular/cli/ember-cli/lib/cli/cli.js:92:22
    at tryCatch (/Users/bracicot/dev/recruitler/node_modules/rsvp/dist/rsvp.js:539:12)
    at invokeCallback (/Users/bracicot/dev/recruitler/node_modules/rsvp/dist/rsvp.js:554:13)
    at /Users/bracicot/dev/recruitler/node_modules/rsvp/dist/rsvp.js:629:16
    at flush (/Users/bracicot/dev/recruitler/node_modules/rsvp/dist/rsvp.js:2414:5)
    at _combinedTickCallback (internal/process/next_tick.js:95:7)
    at process._tickCallback (internal/process/next_tick.js:161:9)

I'm kind of stumped as to what could be causing this short of rolling back NPM. There doesnt seem to be anything online about it either.

UPDATE: NPM added a package-lock.json file. The Invalid Version is coming from there.

UPDATE 2: After reinstalling the CLI I get Cannot find module 'webpack/lib/node/NodeTemplatePlugin' could it be that the package.json and package-lock.json are not in sync?

UPDATE 3: Special thanks to @Dylanb124 Yes NPM5 is certainly buggy, the first issue was the package-lock file being created with incorrect values... There is a lot to this issue and I have resolved it. My dev partner was able to get NPM 5 working with a fresh NG project. Therefore we matched the working version against our repo until it built properly. The main conflicts were packages that supported node and mongo (hammer.js) and some others that I was able to remove permanently. (some cleanup was due anyways) in the end we were able to get it running. I would recommend waiting as long as possible to upgrade to NPM 5x

like image 366
Ben Racicot Avatar asked Jun 02 '17 12:06

Ben Racicot


1 Answers

What worked for me on npm 5.0.2

  1. delete node_modules

  2. rm -f package-lock.json && npm install

like image 153
Ced Avatar answered Sep 21 '22 02:09

Ced