dargue3
dargue3

Reputation: 2942

Karma Browserify bundle error

Trying to get a combination of vue.js, Karma, and browserify to play nicely for unit-testing. Currently I believe that my browserify process is not working correctly. When the test parses my file, it reports back with an error on line 1:

17 07 2016 00:40:44.501:ERROR [framework.browserify]: bundle error

./../../../tests/js/site/Validator.spec.js:1
import Validator from './mixins/Validator.js'
^
ParseError: 'import' and 'export' may appear only with 'sourceType: module'

The key section of my karma.conf.js file looks like the following:

preprocessors: {
    './../../../tests/js/**/*.js': ['browserify']
},

browserify: {
    debug: true, // debug=true to generate source maps
    transform: [ ['vueify', {'presets' : ['es2015']}] ]
},

I've been digging and it sounds like this is due to browserify not handling ES6 very well and it requires presets for babel to do it's thing. Any help would be appreciated.

Upvotes: 1

Views: 2844

Answers (1)

dargue3
dargue3

Reputation: 2942

A slight tweak of my browserify section in karma.conf.js seemed to do the trick. It works now after changing it to the following:

browserify: {
    debug: true,
    transform: [ ['babelify', {presets: ["es2015"]}] ],
},

Upvotes: 6

Related Questions