javascript - PhantomJS Karma SyntaxError for export - Stack Overflow

admin2025-04-19  0

I am having an issue when running Karma and PhantomJS. When I try to run I get this in the console:

22 03 2016 14:58:47.865:WARN [karma]: No captured browser, 
open http://localhost:9876/
22 03 2016 14:58:47.875:INFO [karma]: Karma v0.13.22 server 
started at http://localhost:9876/
22 03 2016 14:58:47.879:INFO [launcher]: Starting browser PhantomJS
22 03 2016 14:58:48.336:INFO [PhantomJS 2.1.1 (Mac OS X 0.0.0)]:
Connected on socket /#lBe2M4kLKnN8N5x0AAAA with id 55603904
PhantomJS 2.1.1 (Mac OS X 0.0.0) ERROR
SyntaxError: Use of reserved word 'export'

I have updated all of my npm modules for karma, webpack, karma-phantomjs, etc., but still don't understand why this is happening. An example of a file that it is not liking:

export default function () {
    // code here
}

Has anyone else run into this trouble and found out how to solve it?

I am having an issue when running Karma and PhantomJS. When I try to run I get this in the console:

22 03 2016 14:58:47.865:WARN [karma]: No captured browser, 
open http://localhost:9876/
22 03 2016 14:58:47.875:INFO [karma]: Karma v0.13.22 server 
started at http://localhost:9876/
22 03 2016 14:58:47.879:INFO [launcher]: Starting browser PhantomJS
22 03 2016 14:58:48.336:INFO [PhantomJS 2.1.1 (Mac OS X 0.0.0)]:
Connected on socket /#lBe2M4kLKnN8N5x0AAAA with id 55603904
PhantomJS 2.1.1 (Mac OS X 0.0.0) ERROR
SyntaxError: Use of reserved word 'export'

I have updated all of my npm modules for karma, webpack, karma-phantomjs, etc., but still don't understand why this is happening. An example of a file that it is not liking:

export default function () {
    // code here
}

Has anyone else run into this trouble and found out how to solve it?

Share Improve this question asked Mar 22, 2016 at 19:04 pertrai1pertrai1 4,32813 gold badges49 silver badges74 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

You should use Webpack as preprocessor: https://github./webpack/karma-webpack

I personally use this one, because it's faster: https://github./aaronjensen/karma-webpack

And you might need to add some polyfills to your karma configuration:

files: [
  './node_modules/babel-polyfill/dist/polyfill.js',
  './node_modules/phantomjs-polyfill/bind-polyfill.js',
  ...
]

You are trying to run ES6 code with PhantomJS but PhantomJS does not seem to support them yet: https://kangax.github.io/pat-table/es6/#phantom

There are some workarounds mentioned e.g.: How to use ES6 with PhantomJS

You should also have a look at https://www.npmjs./package/karma-es6-shim and try that with your code.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1745075285a283530.html

最新回复(0)