const keyword breaking PhantomJS

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.

Author: Fantashit

2 thoughts on “const keyword breaking PhantomJS

  1. 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.

Comments are closed.