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

查看:50
本文介绍了未知错误: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 npminstall -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.

推荐答案

我遇到了同样的问题,我可以通过将 node 降级到 v12.8.1 来修复它

您可以使用 nvm 如下:

安装 nvm

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

刷新.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 -- version

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

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