angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

ng run error on ubuntu

Open sombochea opened this issue 9 years ago • 22 comments

root@localhost:$ ng /usr/local/lib/node_modules/angular-cli/node_modules/@ngtools/json-schema/src/schema-class-factory.js:33 result.push(...indices); ^^^

SyntaxError: Unexpected token ... at exports.runInThisContext (vm.js:53:16) at Module._compile (module.js:374:25) at Object.Module._extensions..js (module.js:417:10) at Module.load (module.js:344:32) at Function.Module._load (module.js:301:12) at Module.require (module.js:354:17) at require (internal/module.js:12:17) at Object. (/usr/local/lib/node_modules/angular-cli/node_modules/@ngtools/json-schema/src/index.js:2:30) at Module._compile (module.js:410:26) at Object.Module._extensions..js (module.js:417:10)

How to resolve it! Please me! on Ubuntu 16.04 LTS

sombochea avatar Feb 18 '17 12:02 sombochea

Just installed the CLI myself this morning from an 'npm install -g angular-cli' and i get exactly the same issue when running 'ng new'.

I'm on MacOS though.

iainplimmer avatar Feb 19 '17 10:02 iainplimmer

You should be using npm install -g @angular/cli

Ionaru avatar Feb 20 '17 09:02 Ionaru

Same problem after running the above command. 'ng new' just gives the following:

iains-iMac:git iain$ ng new iainsangular /usr/local/lib/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. (/usr/local/lib/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)

iainplimmer avatar Feb 20 '17 17:02 iainplimmer

This seems to be occurring too on Win10, with the following:

Node v4.4.7 NPM v4.2.0

Strangely, ng --v causes the same error to pop up.

efbsolis avatar Feb 21 '17 02:02 efbsolis

And this is why you should use the issue template... Especially the 'Versions' section.

Angular CLI uses new Javascript features that aren't available in Node 4, try upgrading Node to 6.9.0 or above.

https://github.com/angular/angular-cli#prerequisites

Ionaru avatar Feb 21 '17 07:02 Ionaru

Thanks Ionaru. Upgraded to v6.9.0 and error immediately disappeared.

dkinsbursky avatar Feb 23 '17 20:02 dkinsbursky

CLI Quickstart at angular.io still mentions at least node 4.x.x in Step 1.

thojo avatar Feb 25 '17 20:02 thojo

@thojo Actually the information has been changed on Github, but the website hasn't updated yet.

Ionaru avatar Feb 25 '17 22:02 Ionaru

I fixed it with updated version of nodejs npm install npm@latest -g

laguiz avatar Feb 27 '17 12:02 laguiz

Yeah I'm sorry about that, it took us a while to update the CLI quickstart. The problem really was node and npm version.

filipesilva avatar Mar 13 '17 17:03 filipesilva

Had the same issue; I updated npm but that didnt solve the issue. So I uninstalled node.js from my computer and installed again, which fixed the problem.

sghaleb1 avatar May 11 '17 14:05 sghaleb1

Same problem with ubuntu, even if you use the newest package via repo install it has still the version 4.X Check your node version node --version Or better use node version manager (nvm)

M4rcDev avatar May 12 '17 18:05 M4rcDev

Try this guys...

npm cache clean -f
npm install -g n
n stable

cdvillagra avatar Jun 19 '17 16:06 cdvillagra

@TheNuclearCat @sghaleb1 Ubuntu (and some other Linux distributions) will not upgrade NodeJS to new major versions, you have to redo the installation steps to upgrade NodeJS.

For example the commands below will install NodeJS 6

curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
sudo apt-get install -y nodejs

And these commands below will install NodeJS 8

curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install -y nodejs

Notice the curl link changed from 6 to 8.

Minor version updates, for example 8.0.0 to 8.1.0, will then get installed with normal system updates.

Ionaru avatar Jun 19 '17 17:06 Ionaru

lonaru, you comment helped me a lot. Thanks very much!

LeonardoSSev avatar Jun 30 '17 20:06 LeonardoSSev

I have same issue on Ubuntu 16.04, @Ionaru comment solve my issue, thanks,

wdranjeet avatar Jul 08 '17 11:07 wdranjeet

@Ionaru's comment solved this for me on ubuntu 17.04. Reason for angular-cli not working was that legacy node was installed. Thank you ionaru!

ekstremedia avatar Jul 16 '17 17:07 ekstremedia

how to update the node ..??? i have tried all the ways to update or upgrade still my node version is v4.2.6?? wt should i do?

deepakpookkote avatar Aug 07 '17 04:08 deepakpookkote

You're probably running into the issue with node and nodejs pointing to different installs. If you tried the following below, then the new version is node and you can remove nodejs.

npm cache clean -f
npm install -g n
n stable

Side note, I had to run npm install @angular/cli to my local working directory and then to my global too at sudo npm install -g @angular/cli.

pjdufour avatar Aug 10 '17 04:08 pjdufour

If you follow the apt install I would suggest to remove any locally installed node first:

sudo rm -rf /usr/local/{lib/node{,/.npm,_modules},bin,share/man}/{npm*,node*,man1/node*}

lrkwz avatar Sep 28 '17 13:09 lrkwz