首页 文章

新的我的应用程序意外令牌=

提问于
浏览
26

我已经通过npm安装了angular2 cli,但是当我尝试使用'ng new my-app'命令创建一个新的typescript角度应用程序时,我不断收到此错误:

C:\Users\nicholas\AppData\Roaming\npm\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.<anonymous> (C:\Users\nicholas\AppData\Roaming\npm\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)

我的NPM版本是4.1.2我的节点版本是4.4.5,根据我的理解,这是安装和使用angular-cli的可接受版本 .

如果有解决方法,请告诉我,我也尝试卸载,清理npm缓存并重新安装,但我一直遇到同样的问题 .

任何和所有的帮助非常感谢,提前感谢!

3 回答

  • 0

    解决如下:

    ashish @ ashish-Inspiron-3521:〜$ sudo su [sudo]密码为ashish:root @ ashish-Inspiron-3521:/ home / ashish #sudo npm cache clean -f npm WARN使用--force我当然希望你知道是什么你在干嘛root @ ashish-Inspiron-3521:/ home / ashish #sudo npm install -gn / usr / local / bin / n - > / usr / local / lib / node_modules / n / bin / n / usr / local /lib└─ ─n@2.1.8

    root @ ashish-Inspiron-3521:/ home / ashish #sudo n stable

    install : node-v9.8.0
       mkdir : /usr/local/n/versions/node/9.8.0
       fetch : https://nodejs.org/dist/v9.8.0/node-v9.8.0-linux-x64.tar.gz
    

    ################################################## ################# 100.0%############################### ################################### 100.0%
    安装:v9.8.0

    root @ ashish-Inspiron-3521:/ home / ashish #root @ ashish-Inspiron-3521:/ home / ashish #sudo ln -sf /usr/local/n/versions/node/9.8.0/bin/node/usr / bin / nodejs root @ ashish-Inspiron-3521:/ home / ashish #sudo n latest

    install : node-v9.9.0
       mkdir : /usr/local/n/versions/node/9.9.0
       fetch : https://nodejs.org/dist/v9.9.0/node-v9.9.0-linux-x64.tar.gz
    

    ################################################## ################# 100.0%
    安装:v9.9.0

    root @ ashish-Inspiron-3521:/ home / ashish #root @ ashish-Inspiron-3521:/ home / ashish#ng -v

    _                      _                 ____ _     ___
    

    / \ _ __ __ _ _ _ | | __ _ _ __ / | | | | / △ \ | ' \ / | | | | |/ _ | ' | | | | | | | / **** | | | | (| | || | | (| | | | | | | _ | | // | ||, |,||,|| __ | _____ | | | /

    Angular CLI:1.7.3节点:9.9.0 OS:linux x64 Angular:... root @ ashish-Inspiron-3521:/ home / ashish #node -v v9.9.0 root @ ashish-Inspiron-3521:/ home /阿希什#

  • 7

    如果您已安装@angular/cli,则需要 NodeJS 更高 6.9.7 ,以及 NPM 3 或更高版本 .

    如果已安装 angular-cli ,则需要 NodeJS 高于 4.4.x ,以及 NPM 3 或更高版本 .

    有关更多信息,请参阅上面的链接并阅读先决条件 .

  • 33

    截至2017-06-03,使用Angular-CLI 1.1.0,NodeJS 7.10.0,npm 5.0.2,Angular 4.1.3,TypeScript 2.3.4,我在Visual Studio中遇到了原始海报(OP)的错误2017年在Task Runner Explorer期间,运行构建任务(在build.json中定义的ng构建) .

    我启动了一个PowerShell提示符,导航到package.json所在的目录,并从命令行调用了ng build,它没有遇到任何错误 .

    这立刻引起了我的怀疑,即它是一个PATH(VS 2017内)问题导致错误出现在VS 2017的Task Runner输出窗口中 .

    果然,在工具/选项/项目和解决方案/ Web包管理/外部工具下,我不得不将$(PATH)的条目移到$(VSINSTALLDIR)\ Web \ External以及(至少在我的情况下)下面 . \ node_modules.bin .

    完成上述所有操作后,我可以右键单击Task Runner Explorer的构建(在“自定义”选项卡下),这次它成功了 .

    在任何人回复之前,请记住以下内容:

    • 这与Visual Studio 2017非常具体,其中正在开发Angular 4.1.3应用程序(希望)与ASP.Net Core 1.1和平共存 .

    • 我全局安装了TypeScript 2.3并在本地安装 .

    • 我有最新的NodeJS和NPM版本(截至撰写本文时至少) .

    • 我用来解决这个问题的技巧可能不适合你 .

    底线:它可能是您的PATH中可能导致错误的位置的顺序 .

相关问题