Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

const keyword breaking PhantomJS #2407

Closed
mattxo opened this issue Apr 28, 2016 · 6 comments
Closed

const keyword breaking PhantomJS #2407

mattxo opened this issue Apr 28, 2016 · 6 comments
Labels

Comments

@mattxo
Copy link

mattxo commented Apr 28, 2016

Webpack appears to be outputting the const keyword instead of the var keyword which is breaking PhantomJS (as it doesn't support ES6 syntax).

...    
/* 2 */
/***/ function(module, exports, __webpack_require__) {    
    "use strict";
    const testing_1 = __webpack_require__(3); // const keyword breaking PhantomJS
    testing_1.describe('App', () => {
...

So PhantomJS reports

PhantomJS 2.1.1 (Windows 8 0.0.0) ERROR
  SyntaxError: Unexpected token 'const'

The file in question (karma-shim.js) is being processed by the karma-webpack preprocessor

karma-shim.js

'use strict';

Error.stackTraceLimit = Infinity;
require('es6-shim');
require('angular2/bundles/angular2-polyfills.js');
require('angular2/testing');

var appContext = require.context('./src', true, /root\.spec\.ts/);

appContext.keys().forEach(appContext);

var testing = require('angular2/testing');
var browser = require('angular2/platform/testing/browser');

testing.setBaseTestProviders(browser.TEST_BROWSER_PLATFORM_PROVIDERS, browser.TEST_BROWSER_APPLICATION_PROVIDERS);

karma.conf.js

...
preprocessors: {
    './karma-shim.js': ['webpack', 'sourcemap']
},

webpack.config.js Is part of generator-ng2-webpack (https://github.com/cmelion/generator-ng2-webpack) but doesn't appear to mention transpilation.

@bebraw bebraw added the bug label Apr 28, 2016
@sokra
Copy link
Member

sokra commented Apr 29, 2016

It's not webpack that emits a const statement. Maybe you have some other preprocessor in place which emits it or the const is in the original file.

@mattxo
Copy link
Author

mattxo commented May 2, 2016

Ah... I think you're right... the ts.config was targeting ES6! Thanks!

@pritishchandak
Copy link

add
compilerOptions {
"noEmitHelpers": true, // this need true for unit test
}
solves this problem

@joeheyming
Copy link

I had this issue. It was terrible. The problem for me was that a loader test regex was too permissive and basically the expose loader was running for files that shouldn't, which was injecting code with const. I was not seeing this issue when running karma with Chrome, because Chrome supports const. But when you run it in Phantomjs, 'const' isn't supported.

Once I locked down the regex to match the exact file, the problem went away

@damiangreen
Copy link

@pritishchandak did you need to install ts-helpers?
@joeheyming can you clarify?
@mattxo what di you target instead? es5?

@joeheyming
Copy link

I had a rule:

{ test: /jquery/ }

This matched any file with jquery in it. Turns out we had a file with jquery in the path:
e.g. some/dir/jquery/main.js
Which got matched, then exposed on the window!

So I updated the test to match:
{ test: /jquery.js$/ }

I did the same with bootstrap.js.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants