nikku / karma-browserify

A fast Browserify integration for Karma that handles large projects with ease

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot use import statement outside a module only on karma-browserify

shirblc opened this issue · comments

Hi,

I have an issue with karma-browserify and bundling up test files. Bundling seems to go perfectly fine when bundling tests separately, but when I try doing it through karma-browserify Karma errors with Uncaught SyntaxError: Cannot use import statement outside a module. On the other hand, when I bundle the tests and then run Karma with that tests file, Karma runs perfectly fine and detects all tests.

I've tried searching online, but I can't seem to be able to figure out what the difference is between the Gulp task (here) and the karma-browserify config (here).

Could anyone help?

Sample repo, ready with the relevant Gulp tasks and Karma config. Just needs to install dependencies and run gulp test.

Thank you!

Never mind, seems to be my error. On a side note, it might be worth replacing 'prebundle' with 'bundle' in the README as it seems to be the updated way to apply transforms and plugins.

Never mind, seems to be my error.

Thanks for the heads up.

On a side note, it might be worth replacing 'prebundle' with 'bundle' in the README as it seems to be the updated way to apply transforms and plugins.

Do you have a reference for me where I can look this one up?

I can't seem to find a direct reference to it, but I haven't found any references to prebundle after 2015, and Browserify's samples (And a lot of the plugins / transforms) use bundle.plugin/transform instead of the prebundle hook, like this:

configure: function(bundle) {
        bundle.plugin('tsify', { target: 'es6' }).transform('browserify-istanbul');
      }

(That's the configuration that worked, by the way).
So 'prebundle' doesn't seem needed anymore (nor did it seem to be working for me, but as said, that seemed to be my error).