karma-webpack: `SyntaxError: Use of reserved word 'import'` when using ES6 with Babel
I’m having a really hard time trying to setup testing in my application. We are using Angular, Webpack, ES6 with Babel.
My relevant files are as follows:
karma.conf.js
require('babel-core/register');
module.exports = require('./karma.conf.babel').default;
karma.conf.babel.js
import webpackDevConfig from './webpackDevConfig'
export default (config) => {
config.set({
frameworks: [
'jasmine'
],
files: [
'test/test_index.js'
],
preprocessors: {
'test/test_index.js': ['webpack']
},
browsers: [
'PhantomJS',
],
singleRun: true,
webpack: webpackDevConfig,
webpackMiddleware: {
noInfo: true
}
});
};
webpackDevConfig.js
export default (config) => {
return {
module: {
loaders: [
{
test: /\.js?$/,
exclude: /(node_modules)/,
loader: 'ng-annotate?map=false!babel-loader?cacheDirectory=true&presets[]=es2015',
},
// ... other loaders
],
},
// ... other config
}
}
test/test_index.js
import 'angular';
import 'angular-mocks/angular-mocks';
const testsContext = require.context('.', true, /.spec$/);
testsContext.keys().forEach(testsContext);
Error is:
10 06 2016 17:34:11.421:INFO [karma]: Karma v0.13.22 server started at http://localhost:9876/
10 06 2016 17:34:11.443:INFO [launcher]: Starting browser PhantomJS
10 06 2016 17:34:12.860:INFO [PhantomJS 2.1.1 (Mac OS X 0.0.0)]: Connected on socket /#4wX21ZNf-Gdt6B2nAAAA with id 30689295
PhantomJS 2.1.1 (Mac OS X 0.0.0) ERROR
SyntaxError: Use of reserved word 'import'
at /Users/rafael/myproject/test/test_index.js:47
npm ERR! Test failed. See above for more details.
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 1
- Comments: 31 (8 by maintainers)
I’m experiencing this issue as well. Weird to see it hasn’t been fixed for almost 2 years
+1
Vuejs, Webpack, Karma -> No preprocessing of both .js and .vue files.
I started seeing this happening when I moved some folders around in my project. Updating the path in karma.conf.js fixed it.
None of the solutions provided aboved worked for me. I can’t manage to make webpack preprocess my file. The only way I could run the test was using laravel-elixir webpack method to precompile the files and then pass the compiled to karma, without using preprocessors. But this isn’t a fix I would like to use, it’s messy and simply a lousy workaround. If anyone could take a look at my conf files and tell me what’s wrong in them I would appreciate it very much.
karma.conf.js
webpack.config.js
package.json
I’m sorry for dropping all this here but I really need someone to tell me what’s wrong. I’ve lost too many hours trying to make this work… thanks!
EDIT: I’m using laravel 5.3 as the base and Vue js 2 as the JS framework.
+1
+1 - same with typescript