angular-cli: Version of @angular/compiler-cli needs to be 2.3.1 or greater. Current version is "undefined".

Bug Report or Feature Request (mark with an x)

- [x] bug report -> please search issues before submitting
- [ ] feature request

Versions.

angular-cli: 1.0.0-beta.28.3 node: 6.10.0 os: darwin x64

Repro steps.

ng build

The log given by the failure.

As a forewarning, we are moving the CLI npm package to “@angular/cli” with the next release, which will only support Node 6.9 and greater. This package will be officially deprecated shortly after.

To disable this warning use “ng set --global warnings.packageDeprecation=false”. Version of @angular/compiler-cli needs to be 2.3.1 or greater. Current version is “undefined”. Error: Version of @angular/compiler-cli needs to be 2.3.1 or greater. Current version is “undefined”. at Object.<anonymous> (…/node_modules/@ngtools/webpack/src/index.js:27:11) at Module._compile (module.js:570:32) at Object.Module._extensions…js (module.js:579:10) … etc …

Desired functionality.

Our build tool cannot crash out of the blue, having changed nothing at all in our code or configurations. Running npm install with specific versions listed for every package in the package.json should not crash the build machine, and every machine of every developer unfortunate enough to have run “npm install” locally.

Mention any other details that might be useful.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 43
  • Comments: 43 (4 by maintainers)

Most upvoted comments

npm install --save-dev @ngtools/webpack@1.2.13 Horrible hack but at least gets it working short of upgrading all your other packages.

The project needs a dev dependency for @angular/compiler-cli. npm install --save-dev @angular/compiler-cli@<your angular version>

@clydin thanks for the tip, but unfortunately that doesn’t work either. Exactly the same result. I guess I’ve got YAAVU (Yet Another Angular Version Update) to slog through now. You understand my point about how if this worked once it should always work, right? This worked just fine a week ago. Now it doesn’t. And no changes to our dependencies in between. The process has to be repeatable or the whole npm packaging and versioning system cannot be trusted.

The only way I can think of for it to break like this is if someone publishes a package with breaking changes without rev-ing the version number or bothering to say anything about it. And that someone was not me. But I’m picking up the pieces.

And to your comment about my “very old” verison of angular, let’s be very precise: that was 6 months ago. Not exactly a geological age.

Since you’re on an old version of angular and a very old beta of the CLI you’ll need to use @aeacusvol suggestion instead. For beta.18 the version of @ngtools/webpack should be 1.1.2.

npm install --save-dev @ngtools/webpack@1.1.2

Also please note that these are beta versions; expect them to break.

Same issue

versions: angular-cli: 1.0.0-rc.0 node: 6.6.0 os: ubuntu 16.04

message: Version of @angular/compiler-cli needs to be 2.3.1 or greater. Current version is “undefined”. Error: Version of @angular/compiler-cli needs to be 2.3.1 or greater. Current version is “undefined”. at Object.<anonymous> (////node_modules/@angular/cli/node_modules/@ngtools/webpack/src/index.js:27:11) at Module._compile (module.js:570:32) at Object.Module._extensions…js (module.js:579:10) at Module.load (module.js:487:32) at tryModuleLoad (module.js:446:12) at Function.Module._load (module.js:438:3) at Module.require (module.js:497:17) at require (internal/module.js:20:19) at Object.<anonymous> (////node_modules/@angular/cli/tasks/eject.js:10:19) at Module._compile (module.js:570:32) at Object.Module._extensions…js (module.js:579:10) at Module.load (module.js:487:32) at tryModuleLoad (module.js:446:12) at Function.Module._load (module.js:438:3) at Module.require (module.js:497:17) at require (internal/module.js:20:19)

Same for 1.0.0-beta.18. A compiler-cli dev dependency (our angular version is 2.1.1) as suggested by @clydin does not work.

I get this error using VS Code on Zorin Linux (Ubuntu 16.04): It says that it needs to be 2.3.1 or higher, but doesn’t accept 5.05!

Exception has occurred: CLR/System.AggregateException
An exception of type 'System.AggregateException' occurred in System.Private.CoreLib.dll but was not handled in user code: 'One or more errors occurred.'
 Inner exceptions found, see $exception in variables window for more details.
 Innermost exception 	 Microsoft.AspNetCore.NodeServices.HostingModels.NodeInvocationException : Version of @angular/compiler-cli needs to be 2.3.1 or greater. Current version is "5.0.5".
Error: Version of @angular/compiler-cli needs to be 2.3.1 or greater. Current version is "5.0.5".
    at Object.<anonymous> 

I have a solution if you aren’t ready to upgrade angular-cli or @angular/cli.

It can be done using shrinkwrap and some hoop-jumping. Even though some hackery is invloved, it does result in a fileset that can perform a fresh build from source.

  1. npm uninstall -g angular-cli (getting rid of global instance as we won’t be shirnkwrapping that).
  2. npm cache clean (at this point I’m assuming you currently have your desired version of angular-cli installed in your project’s node_modules)
  3. Delete the ‘webpack’ folder from <project>\node_modules@ngtools and replace it with a version that you know works (in my case this was 1.1.4)
  4. Manually edit <project>\node_modules\angular-cli\package.json and change the dependency from "@ngtools/webpack": "latest" to "@ngtools/webpack": "1.1.4" (bear with me - this is only temporary)
  5. npm shrinkwrap

That’s it, now shrinkwrap.json will contain the locked down dependenies that will work for you! From here you should be able to delete node_modules and do ‘npm install’ successfully.

One more thing, because we’re now using a local version of ‘ng’, you’ll need do update your ‘scripts’ section of package.json - replace any reference to ‘ng’ with 'node node_modules/angular-cli/bin/ng'. Also as @mildfuzz points out, you might want to add a script line for compile, eg:- "compile": "node node_modules/angular-cli/bin/ng build"

Heya, I just want to chime in even though @clydin has already offered a number of solutions.

This issue is related to https://github.com/angular/angular-cli/pull/5118, and the fact that on older versions of the CLI the @ngtools/webpack dependency was rather loose.

We’ve since fixed @ngtools/webpack to not be as loose. The @angular/compiler-cli dependency has also been there for a while now, and is explicitly mentioned in https://github.com/angular/angular-cli/wiki/stories-rc-update.

I’m sorry that this release wrecked havoc in older releases, and that it has caused you to have to spend time updating and fixing packages.

This isn’t something that you can expect to be fixed without an update on your side though. I’m sorry but it’s just not. beta.18 and beta.28.3 are versions that were never meant to be supported long term and we never tried to hide that. The only version for which there is long term support is 1.0 when it is out.

The only solution that I think can help really old versions is to force the @ngtools/webpack version as @clydin recommended.

I’d also like to highlight this comment:

You understand my point about how if this worked once it should always work, right? This worked just fine a week ago. Now it doesn’t.

I understand that this is desirable. But you do not get that guarantee out of the box with npm. You need to either use npm shrinkwrap or yarn to have reproducible dependency installs.

Unfortunately, the fix I suggested can only solve the case of the undefined version.

For those using beta versions, it is strongly recommended to upgrade to the latest RC. Due to the inherent nature of beta versions, active support of past beta versions is not currently viable. There is also an extensive list of bug fixes and feature improvements since the early betas.

For those interested in upgrading, there is a guide detailing the necessary steps which can be found here: https://github.com/angular/angular-cli/wiki/stories-rc-update If while following the guide any deficiencies are encountered, please open an issue so that the guide can be as complete and straightforward as possible.

I encountered the same issue

Version of @angular/compiler-cli needs to be 2.3.1 or greater. Current version is “undefined”. Error: Version of @angular/compiler-cli needs to be 2.3.1 or greater. Current version is “undefined”. at Object.<anonymous> (/home/rxjs/work/ng2-tdd/angular-tdd/node_modules/@ngtools/webpack/src/index.js:27:11) at Module._compile (module.js:571:32) at Object.Module._extensions…js (module.js:580:10) at Module.load (module.js:488:32) at tryModuleLoad (module.js:447:12) at Function.Module._load (module.js:439:3) at Module.require (module.js:498:17) at require (internal/module.js:20:19) at Object.<anonymous> (/home/rxjs/work/ng2-tdd/angular-tdd/node_modules/angular-cli/models/webpack-build-typescript.js:5:17) at Module._compile (module.js:571:32) at Object.Module._extensions…js (module.js:580:10) at Module.load (module.js:488:32) at tryModuleLoad (module.js:447:12) at Function.Module._load (module.js:439:3) at Module.require (module.js:498:17) at require (internal/module.js:20:19) at Object.<anonymous> (/home/rxjs/work/ng2-tdd/angular-tdd/node_modules/angular-cli/models/webpack-config.js:2:34) at Module._compile (module.js:571:32) at Object.Module._extensions…js (module.js:580:10) at Module.load (module.js:488:32) at tryModuleLoad (module.js:447:12) at Function.Module._load (module.js:439:3) at Module.require (module.js:498:17) at require (internal/module.js:20:19) at Object.<anonymous> (/home/rxjs/work/ng2-tdd/angular-tdd/node_modules/angular-cli/tasks/build-webpack.js:6:24) at Module._compile (module.js:571:32) at Object.Module._extensions…js (module.js:580:10) at Module.load (module.js:488:32) at tryModuleLoad (module.js:447:12) at Function.Module._load (module.js:439:3) at Module.require (module.js:498:17) at require (internal/module.js:20:19) at Object.<anonymous> (/home/rxjs/work/ng2-tdd/angular-tdd/node_modules/angular-cli/commands/build.js:3:23) at Module._compile (module.js:571:32) at Object.Module._extensions…js (module.js:580:10) at Module.load (module.js:488:32) at tryModuleLoad (module.js:447:12) at Function.Module._load (module.js:439:3) at Module.require (module.js:498:17) at require (internal/module.js:20:19) at Class.includedCommands (/home/rxjs/work/ng2-tdd/angular-tdd/node_modules/angular-cli/addon/index.js:21:16) at /home/rxjs/work/ng2-tdd/angular-tdd/node_modules/angular-cli/angular-cli/lib/models/project.js:392:61 at Array.forEach (native) at Project.addonCommands (/home/rxjs/work/ng2-tdd/angular-tdd/node_modules/angular-cli/angular-cli/lib/models/project.js:391:15) at Project.eachAddonCommand (/home/rxjs/work/ng2-tdd/angular-tdd/node_modules/angular-cli/angular-cli/lib/models/project.js:426:30) at module.exports (/home/rxjs/work/ng2-tdd/angular-tdd/node_modules/angular-cli/angular-cli/lib/cli/lookup-command.js:33:13) at CLI.<anonymous> (/home/rxjs/work/ng2-tdd/angular-tdd/node_modules/angular-cli/angular-cli/lib/cli/cli.js:34:26) at tryCatch (/home/rxjs/work/ng2-tdd/angular-tdd/node_modules/rsvp/dist/rsvp.js:539:12) at invokeCallback (/home/rxjs/work/ng2-tdd/angular-tdd/node_modules/rsvp/dist/rsvp.js:554:13) at publish (/home/rxjs/work/ng2-tdd/angular-tdd/node_modules/rsvp/dist/rsvp.js:522:7) at flush (/home/rxjs/work/ng2-tdd/angular-tdd/node_modules/rsvp/dist/rsvp.js:2414:5) at _combinedTickCallback (internal/process/next_tick.js:67:7) at process._tickCallback (internal/process/next_tick.js:98:9)

@filipesilva points all received and accepted here but it’s a huge bummer when these things happen (I’ve come to assume they are unfortunate but inevitable when working with node + npm). While it sucks, the versions facing the issue were clearly beta and so people need to accept the fact that they may encounter issues and not receive long term support.

npm shrinkwrap however does not help with this one due to the very loose latest tag that was used. We use shrinkwrap with our project and the issue still occurs. Oh well, an Angular + Angular CLI upgrade was overdue for us anyways… 😉

So how about updating angular CLI, then just starting a new app (ng new <app-name>) and using the packages from the new app? As my solution doesnt have many third party dependencies outside of corre angular. Should that work?

Here is the angular-cli Git Page details:

If you’re using Angular CLI beta.28 or less, you need to uninstall angular-cli package. It should be done due to changing of package’s name and scope from angular-cli to @angular/cli:

npm uninstall -g angular-cli npm uninstall --save-dev angular-cli To update Angular CLI to a new version, you must update both the global package and your project’s local package.

Global package:

npm uninstall -g @angular/cli npm cache clean npm install -g @angular/cli@latest Local project package:

rm -rf node_modules dist # use rmdir /S/Q node_modules dist in Windows Command Prompt; use rm -r -fo node_modules,dist in Windows PowerShell npm install --save-dev @angular/cli@latest npm install