27

I have installed the angular2 cli via npm, but when I try to create a new typescript angular app with the command 'ng new my-app' I keep getting this error:

C:\Users\nicholas\AppData\Roaming\npm\node_modules\@angular\cli\models\config\config.js:15
    constructor(_configPath, schema, configJson, fallbacks = []) {
                                                           ^

SyntaxError: Unexpected token =
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:373:25)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (C:\Users\nicholas\AppData\Roaming\npm\node_modules\@angular\cli\models\config.js:2:18)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)

My NPM version is 4.1.2 My node version is 4.4.5 which from my understanding are acceptable versions for installing and using the angular-cli.

Please let me know if there is a fix to this, I have also tried uninstalling, cleaning npm cache and reinstalling but I keep getting the same issue.

Any and all help is very appreciated, thanks in advance!

Heretic Monkey
  • 11,687
  • 7
  • 53
  • 122
Nicholas Pesa
  • 2,156
  • 2
  • 24
  • 45
  • 1
    You have to download `node` version 6.9 or higher. – kind user Feb 10 '17 at 18:25
  • Before anyone rushes off to ask for code, this looks like an error coming from *within* Angular2. Perhaps you should also check the GitHub site for it to see if there are any open bugs? – Makoto Feb 10 '17 at 18:25
  • 2
    @Kinduser how come the Angular CLI quickstart guide specifies that I need node version 4.x.x or higher? – Nicholas Pesa Feb 10 '17 at 18:27
  • @Makoto thank you, I will check for open bugs. – Nicholas Pesa Feb 10 '17 at 18:27
  • I had the same bug today `C:\Projects>ng new sjerd C:\Users\sjerd\AppData\Roaming\npm\node_modules\@angular\cli\models\config\config.js:15 constructor(_configPath, schema, configJson, fallbacks = []) { ^ SyntaxError: Unexpected token =` – Sjoerd de Wit Feb 10 '17 at 18:31
  • Your environment has been set up for using Node.js 5.7.1 (x64) and npm. – Sjoerd de Wit Feb 10 '17 at 18:32

3 Answers3

34

If you have installed @angular/cli, you need NodeJS higher 6.9.7, together with NPM 3 or higher.

If you have installed angular-cli, you need NodeJS higher than 4.4.x, together with NPM 3 or higher.

For more see the links above and read the prerequisites.

Suren Srapyan
  • 66,568
  • 14
  • 114
  • 112
  • 1
    This answer would be better if you referenced some authority. That way it could be updated if those version numbers change. – Heretic Monkey Feb 10 '17 at 18:40
  • thank you for the answer, this is true. I did need NodeJS 6.9.7 or higher, however the tutorial for this specifically states that you only need NodeJS 4.x.x or higher, check here: https://angular.io/docs/ts/latest/cli-quickstart.html , so it is misleading and I would not have known unless by asking the question here. – Nicholas Pesa Feb 10 '17 at 19:01
  • @Kinduser you were definitely right, I just try to follow the instructions diligently, especially when I am following instructions from Google. Need to post the answer quicker ;) nonetheless Thank You! – Nicholas Pesa Feb 10 '17 at 19:07
  • 2
    why are there two cli's that can be installed? What's the difference? Is a certain scenario call for a specific one? Isn't one a dependency in the project.json and one is a devdependency in the project.json ? – default_noob_network Feb 17 '17 at 19:45
  • The reason for the separate dependencies is separating the 2 versions of Angular right now. Angular 2 is still in development and needs the @angular/cli dependency, while Angular 1 is still using the angular/cli. – Nicholas Pesa Feb 20 '17 at 19:14
  • Excellent Answer. – Abhishek Sharma Sep 09 '17 at 05:01
7

As of 2017-06-03, using Angular-CLI 1.1.0, NodeJS 7.10.0, npm 5.0.2, Angular 4.1.3, TypeScript 2.3.4, I experienced the error of the Original Poster (OP) in Visual Studio 2017 during Task Runner Explorer, running the build task (ng build as defined in package.json).

I launched a PowerShell prompt, navigated to the directory where the package.json lives, and invoked ng build from the command line, and it experienced zero errors.

That immediately raised my suspicions that it was a PATH (within VS 2017) issue that was causing the error to appear in VS 2017's Task Runner output window.

Sure enough, under Tools / Options / Projects and Solutions / Web Package Management / External Tools, I had to move the entry for $(PATH) up above $(VSINSTALLDIR)\Web\External and (in my case at least) below .\node_modules.bin.

Once I did all of the above, I was able to right-click on build (under the Custom tab) of Task Runner Explorer and this time it was successful.

Before anybody replies, keep in mind the following:

  1. This is VERY SPECIFIC to Visual Studio 2017 in which an Angular 4.1.3 application is being developed to (hopefully) peacefully co-exist with ASP.Net Core 1.1.
  2. I have TypeScript 2.3 globally installed and locally installed.
  3. I have the very latest NodeJS and NPM editions (as of the time of writing this post at least).
  4. The techniques I used that resolved this issue for me may not work for you.

Bottom line: it might be the order of where things are in your PATH that might be causing the error.

user3785010
  • 1,029
  • 1
  • 10
  • 11
0

solved as followes:

do

ashish@ashish-Inspiron-3521:~$ sudo su [sudo] password for ashish: root@ashish-Inspiron-3521:/home/ashish# sudo npm cache clean -f npm WARN using --force I sure hope you know what you are doing. root@ashish-Inspiron-3521:/home/ashish# sudo npm install -g n /usr/local/bin/n -> /usr/local/lib/node_modules/n/bin/n /usr/local/lib └── n@2.1.8

root@ashish-Inspiron-3521:/home/ashish# sudo n stable

 install : node-v9.8.0
   mkdir : /usr/local/n/versions/node/9.8.0
   fetch : https://nodejs.org/dist/v9.8.0/node-v9.8.0-linux-x64.tar.gz
################################################################## 100.0% ################################################################## 100.0%

installed : v9.8.0

root@ashish-Inspiron-3521:/home/ashish# root@ashish-Inspiron-3521:/home/ashish# sudo ln -sf /usr/local/n/versions/node/9.8.0/bin/node /usr/bin/nodejs root@ashish-Inspiron-3521:/home/ashish# sudo n latest

 install : node-v9.9.0
   mkdir : /usr/local/n/versions/node/9.9.0
   fetch : https://nodejs.org/dist/v9.9.0/node-v9.9.0-linux-x64.tar.gz
################################################################## 100.0%

installed : v9.9.0

root@ashish-Inspiron-3521:/home/ashish# root@ashish-Inspiron-3521:/home/ashish# ng -v

_                      _                 ____ _     ___

/ \ _ __ __ _ _ _| | __ _ _ __ / | | | | / △ \ | ' \ / | | | | |/ _ | '| | | | | | | / \| | | | (| | || | | (| | | | || |_ | | // __| ||__, |__,||__,|| __|_____|| |/

Angular CLI: 1.7.3 Node: 9.9.0 OS: linux x64 Angular: ... root@ashish-Inspiron-3521:/home/ashish# node -v v9.9.0 root@ashish-Inspiron-3521:/home/ashish#

Ashish Kamble
  • 2,555
  • 3
  • 21
  • 29