【问题标题】:Angular CLI error in console控制台中的 Angular CLI 错误
【发布时间】:2017-03-09 17:20:27
【问题描述】:

我真的希望有人能对此有所了解,因为它让我发疯。我收到以下控制台错误:

Uncaught SyntaxError: Unexpected token import
at eval (<anonymous>)
at webpackJsonp.12.module.exports (addScript.js:9)
at Object.512 (vendor.ts?d8d9:1)
at __webpack_require__ (bootstrap 9a38e78…:52)
at Object.1054 (scripts.bundle.js:31)
at __webpack_require__ (bootstrap 9a38e78…:52)
at webpackJsonpCallback (bootstrap 9a38e78…:23)
at scripts.bundle.js:1

这是由我的 vendor.ts 文件中的modernizrn 引起的:

import './modernizr.js';

我不确定的一件事是它应该在 vendor.ts 文件中还是在 angular-cli.json 文件的脚本部分中。我一直在尝试找出 vendor.ts 和 scripts 部分之间的区别,但我没有运气。如果有人能告诉我,那就太好了。

无论如何,如果我尝试在 angular-cli.json 的脚本部分中包含modernizr,那么项目将无法构建。有谁可以帮我离开这里吗?仅仅是modernizr无法与Angular 2一起正常工作还是我(更有可能),任何帮助将不胜感激。

【问题讨论】:

    标签: angular modernizr


    【解决方案1】:

    下面是如何让它工作:

    1. 下载并安装modernizr: npm install --save-dev modernizr

    2. 在命令行编译: node .\node_modules\modernizr\bin\modernizr -c .\node_modules\modernizr\lib\config-all.json

    3. 将生成的modernizr.js 放到“src”目录下。或任何你想要的地方。

    4. 将它添加到脚本下的 angular-cli.json。该路径是相对于您的“src”目录的。

      “脚本”:[ “./modernizr.js” ],

    【讨论】:

    • 感谢博彦,它奏效了。那么你如何决定天气是在 angular-cli.json 的脚本部分还是在 ventor.ts 文件中放一些东西呢?
    • 这似乎不是一个非常可维护的过程。你有没有找到更好的方法来做到这一点?
    • 从那以后我就没用过modernizr。这个过程适用于当时没有 Angular 或 TypeScript 版本的桥梁的 JS 库。
    猜你喜欢
    • 2018-03-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-03
    • 2021-04-25
    • 1970-01-01
    • 2020-05-22
    相关资源
    最近更新 更多