nikku / karma-browserify

A fast Browserify integration for Karma that handles large projects with ease
MIT License
321 stars 49 forks source link

karma-browserify + aliasify + proxquireify result in `Cannot find module` #160

Closed ds82 closed 8 years ago

ds82 commented 8 years ago

As the title suggests, I'm not able to get karma-browserify, aliasify and proxquireify to work together. I opened the bug here, because it works if I just use browserify with aliasify & proxquireify to build the bundle, but not if I do it with karma-browserify.

I created a demo repo to reproduce the behaviour: https://github.com/ds82/karma-proxyquire-aliasify-test

Clone and npm install. Then you can build two test bundles with node browserify.build.js -> bundles are in build/{bundle,test}.js

The file spec/main.spec.js loads a dependency some-dep which does not really exist, but is aliased via aliasify to src/dep.js. If you look at build/test.js the aliased file src/dep.js got included -> all fine :thumbsup:

Now run karma: karma start karma.conf.js

that results in:

Chrome 47.0.2526 (Mac OS X 10.10.5) ERROR
  Uncaught Error: Cannot find module 'some-dep'
  at /var/folders/0p/b7pdm54d26q8db2qsxtxb3z80000gn/T/19a162a46249643aa983a2c5f2ad3356.browserify:54 <- /Users/dsaenger/code/karma-proxyquire-aliasify-test/node_modules/proxyquireify/lib/prelude.js:54:0

If I'm not missing something, I use the same config for karma-browserify in karma.conf.js as I do for browserify in browserify.build.js.

I'm thankful for any guidance here ..

nikku commented 8 years ago

Try to use the browserify configuration instead of bundle.transform as shown in the project readme.

nikku commented 8 years ago

The reason you might run into trouble is that prebundle is called with every bundle, registering your transform + plugin repeatedly.