SyntaxError:用于test.es5.js的意外令牌'const' [英] SyntaxError: Unexpected token 'const' for testing.es5.js

查看:101
本文介绍了SyntaxError:用于test.es5.js的意外令牌'const'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已切换到 Angular4.0.0-rc.1 , 看来ES5测试包包含ES2015代码.

I've switched to Angular4.0.0-rc.1 and it looks like ES5 testing bundles contain ES2015 code.

我收到此错误:

PhantomJS 2.1.1 (Mac OS X 0.0.0) ERROR
  SyntaxError: Unexpected token 'const'
    at webpack:///~/@angular/core/@angular/core/testing.es5.js:10:0 <- src/test.ts:16345

还在Angular仓库中发现了相关问题.

Also found related issue on Angular repo.

推荐答案

我刚刚创建了一个基本的Angular项目,并且在PhantomJS集成中存在相同(或相似)的问题.

I just created a basic Angular project and had the same (or similar) issue with PhantomJS integration.

PhantomJS 2.1.1 (Mac OS X 0.0.0) ERROR
  SyntaxError: Unexpected token 'const'
  at webpack:///src/app/app.component.ts:1:0 <- src/test.ts:63184

我们的团队成功了,这就是我们在文档中所扔的东西:

PhantomJS是可用于自动化测试的无头(又称无GUI)浏览器. 当前,PhantomJS有一个局限性,因为它仅支持

Our team got it to work and here's what we tossed in our documentation:

PhantomJS is a headless (aka, no GUI) browser that can be used for automated testing. Currently, PhantomJS has a limitation in that it only supports the ES5 standard.

  1. npm install -g phantomjs-prebuilt
  2. npm install --save-dev karma-phantomjs-launcher
    • 在karma.conf.js中
  1. npm install -g phantomjs-prebuilt
  2. npm install --save-dev karma-phantomjs-launcher
    • in karma.conf.js
  1. 在插件部分添加require('karma-phantomjs-launcher')
  2. PhantomJS添加到浏览器
  1. add require('karma-phantomjs-launcher') to the plugins section
  2. add PhantomJS to the browsers

    src/polyfill.ts中的
  • in src/polyfill.ts
  1. 添加import 'intl'; (在底部取消注释)
  2. 在常绿需求部分添加import "core-js/client/shim";
  1. add import 'intl'; (uncomment at the bottom)
  2. add import "core-js/client/shim"; to the Evergreen requirements section

  • 将目标设置为es5.

假设一切顺利,测试应该可以进行.

Assuming all goes well, testing should work.

有关如何触发测试运行的一些示例:

Some examples on how to trigger a test run:

  • ng test --browsers PhantomJS --singleRun true
  • ./node_modules/karma/bin/karma start ./karma.conf.js --browsers PhantomJS --singleRun true
  • ng test --browsers PhantomJS --singleRun true
  • ./node_modules/karma/bin/karma start ./karma.conf.js --browsers PhantomJS --singleRun true

这篇关于SyntaxError:用于test.es5.js的意外令牌'const'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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