Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SyntaxError: Unexpected token 'const' for testing.es5.js

Tags:

angular

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

I'm getting this error:

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

Also found related issue on Angular repo.

like image 968
Stepan Suvorov Avatar asked Jul 05 '26 10:07

Stepan Suvorov


1 Answers

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

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
    • in karma.conf.js
      1. add require('karma-phantomjs-launcher') to the plugins section
      2. add PhantomJS to the browsers
  3. npm install --save intl
    • in src/polyfill.ts
      1. add import 'intl'; (uncomment at the bottom)
      2. add import "core-js/client/shim"; to the Evergreen requirements section
  4. In src/tsconfig.spec.json (or whatever typescript config is used for tests)
    • Set the target to 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
like image 180
user01CU812 Avatar answered Jul 07 '26 06:07

user01CU812



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!