控制台中的Angular CLI错误 [英] Angular CLI error in console

查看:129
本文介绍了控制台中的Angular CLI错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I really hope someone can shead some light on this as its driving me mad. I'm getting the following console error:

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引起的:

It is being caused by modernizrn in my vendor.ts file:

import './modernizr.js';

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

One thing I'm not sure of is if it should be in the vendor.ts file or in the scripts section of the angular-cli.json file. I've been trying to work out what the difference is between the vendor.ts and scripts section are but I've had no luck. If anyone can tell me that would be great.

无论如何,如果我尝试将modernizr包含在angular-cli.json的脚本部分中,则该项目将无法构建.有人可以帮我从这里出去吗?仅仅是因为modernizr无法在Angular 2中正常使用,还是我(更有可能),任何帮助将不胜感激.

Anyway, if I try and include modernizr in the scripts section in angular-cli.json then the project won't build. Can anyone help me out here? Is it just that modernizr can't work properly with Angular 2 or is it me (more likely), any help will be much appreciated.

推荐答案

以下是如何使其工作的方法:

Here is how to get it working:

  1. 使用以下命令下载并安装modernizr: npm install --save-dev modernizr

  1. Download and install modernizr with: npm install --save-dev modernizr

在命令行上对其进行编译: node .\node_modules\modernizr\bin\modernizr -c .\node_modules\modernizr\lib\config-all.json

Compile it on the command line: node .\node_modules\modernizr\bin\modernizr -c .\node_modules\modernizr\lib\config-all.json

将生成的modernizr.js放入"src"目录中.或您想要的任何地方.

Take the generated modernizr.js and put it in the "src" directory. Or anywhere you want.

将其添加到脚本下的angular-cli.json中.该路径是相对于您的"src"目录的.

Add it to your angular-cli.json, under scripts. The path is relative to your 'src' directory.

脚本":[ "./modernizr.js" ]

"scripts": [ "./modernizr.js" ],

这篇关于控制台中的Angular CLI错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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