未知错误:SyntaxError:ng命令上出现意外的标记“导出" [英] Unknown error: SyntaxError: Unexpected token 'export' on ng command

查看:80
本文介绍了未知错误:SyntaxError:ng命令上出现意外的标记“导出"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试学习Angular
我已按照此处的步骤操作: https://angular.io/guide/setup-local 在Ubuntu 18.04.5 LTS上安装它

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

当我尝试使用ng new创建一个新项目时,出现错误:

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'

我通过 sudo npm install -g @ angular/cli 安装了它,但没有出错.

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

我已经清除了节点 sudo apt-get purge nodejs ,然后重新安装并删除了ng sudo npm remove -g @ angular/cli ,然后再次重新安装了 sudo npm安装-g @ angular/cli ,仍然会收到此错误.有什么想法吗?

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?

最初,系统上有一个较旧的nodejs版本;我升级到14.x.导出是ES6的一部分,也许与它有关?我似乎无法弄清楚.

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.

推荐答案

我遇到了同样的问题,可以通过将节点降级到v12.8.1来解决此问题

您可以按以下方式使用 nvm :

You could use nvm as follows:

安装nvm

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

刷新.profile

refresh .profile

source ~/.profile

安装节点v12.8.1

install node v12.8.1

nvm install v12.8.1

检查您使用的是12.8.1版本

check that you are using the 12.8.1 version

nvm list

再次检查ng

ng -- version

这篇关于未知错误:SyntaxError:ng命令上出现意外的标记“导出"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆