Karma + Webpack + PhantomJS: SyntaxError: Unexpected token 'const'
beagleknight opened this issue · 2 comments
beagleknight commented
Hi there!
I created a new project and installed chai-enzyme@^0.6.1
. When I try to run my tests I receive the following error:
PhantomJS 2.1.1 (Linux 0.0.0) ERROR
SyntaxError: Unexpected token 'const'
at app/frontend/entry.test.js:21599
I tried the same configuration with chai-enzyme@^0.4.1
and it works. Do you have any idea what it could be?
I'm using the following karma.conf.js
:
module.exports = function(config) {
config.set({
basePath: '',
frameworks: ['jasmine'],
files: [
'app/frontend/entry.test.js'
],
preprocessors: {
'app/frontend/entry.test.js': ['webpack', 'sourcemap']
},
webpack: {
resolve: {
extensions: ['', '.js', '.jsx']
},
module: {
noParse: [
/\/sinon\.js/
],
loaders: [
{
test: /\.jsx?$/,
exclude: /(node_modules|bower_components)/,
loaders: ['babel', 'eslint']
}
]
},
externals: {
'cheerio': 'window',
'react/lib/ExecutionEnvironment': true,
'react/lib/ReactContext': true,
'react/addons': true
}
},
webpackServer: {
noInfo: true
},
plugins: [
'karma-webpack',
'karma-jasmine',
'karma-sourcemap-loader',
'karma-chrome-launcher',
'karma-phantomjs-launcher'
],
reporters: ['progress'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['PhantomJS'],
singleRun: false
})
};
korbin commented
My guess is this is your .babelrc - please make sure you have (babel-)preset-es2015
in there to compile const
back down to var
for PhantomJS and other older JS clients.
beagleknight commented
I'm closing this because now it's working well. I have updated a lot of things and started using webpack 2 so I'm not sure what was the issue 😄 .