Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unknown error: SyntaxError: Unexpected token 'export' on ng command

Tags:

I'm trying to learn Angular
I've followed the steps here: https://angular.io/guide/setup-local to get it setup on Ubuntu 18.04.5 LTS

When I try to create a new project with ng new I get an error:

$ node -v
v14.12.0

$ npm -v
6.14.8

$ ng new test
Unknown error: SyntaxError: Unexpected token 'export'

$ ng -v
Unknown error: SyntaxError: Unexpected token 'export'

I installed it via sudo npm install -g @angular/cli which gave no errors.

I've purged node sudo apt-get purge nodejs and reinstalled and removed ng sudo npm remove -g @angular/cli then reinstalled again sudo npm install -g @angular/cli, still get this error. Any ideas?

There was an older version of nodejs on the system originally; I upgraded to 14.x. Export is part of ES6, perhaps it's related? I can't seem to figure it out.

like image 812
Jeff Avatar asked Sep 24 '20 17:09

Jeff


2 Answers

I had the same issue and I could fix it by downgrading node to v12.8.1

You could use nvm as follows:

install nvm

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash

refresh .profile

source ~/.profile

install node v12.8.1

nvm install v12.8.1

check that you are using the 12.8.1 version

nvm list

check ng again

ng -- version
like image 69
Yacine Marouf Avatar answered Sep 19 '22 19:09

Yacine Marouf


You are using an incompatible NodeJs version. Install a lower version.

More information here (webarchive version).

like image 26
progm Avatar answered Sep 20 '22 19:09

progm