ng new 失败并显示“SyntaxError: Unexpected token =";在 Ubuntu 上 [英] ng new fails with "SyntaxError: Unexpected token =" on Ubuntu

查看:57
本文介绍了ng new 失败并显示“SyntaxError: Unexpected token =";在 Ubuntu 上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 Ubuntu 16.04.3 LTS,我使用 sudo apt-get install npm node 安装了 npm 和 node.之后,我使用 sudo npm install @angular/cli -g 安装了 @angular/cli.

I'm on Ubuntu 16.04.3 LTS, and I installed npm and node by using sudo apt-get install npm node. After that I installed @angular/cli with sudo npm install @angular/cli -g.

但是当我尝试使用 ng new hello-world 创建一个新项目时,它失败并显示以下错误:

But when I try to create a new project with ng new hello-world, it fails with this error:

/usr/local/lib/node_modules/@angular/cli/models/config/config.js:17
    constructor(_configPath, schema, configJson, fallbacks = []) {
                                                           ^

SyntaxError: Unexpected token =
    at exports.runInThisContext (vm.js:53:16)

如何让 ng new 工作?

推荐答案

原来是因为 Ubuntu 在 repos 中有一个旧版本的 node.我按照 https://nodejs.org 上的说明安装了更新版本,从而修复了错误/en/download/package-manager/

It turned out it was because Ubuntu has an old version of node in the repos. I fixed the error by installing a more recent version following the instructions at https://nodejs.org/en/download/package-manager/

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

这篇关于ng new 失败并显示“SyntaxError: Unexpected token =";在 Ubuntu 上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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