nikku / karma-browserify

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

Not able to require module packages with CommonJS #204

Closed JuanCaicedo closed 7 years ago

JuanCaicedo commented 7 years ago

I mentioned this problem in https://github.com/jamesshore/quixote/pull/37, but the maintainer thought the problem might be with this plugin.

To recreate, you can

$ git clone https://github.com/JuanCaicedo/tdd-css.git
$ cd tdd-css
$ git fetch origin
$ git checkout quixote-published
$ npm install
$ npm test

Any help would be appreciated! 😃

bendrucker commented 7 years ago

If you point browserify directly at one of your test modules will it bundle?

JuanCaicedo commented 7 years ago

Thanks for the quick response! I tried pointing browserify directly on this branch https://github.com/JuanCaicedo/tdd-css/tree/manual-browserify

If I do these steps

$ npm install
$ browserify test/accent-box.js -o lib-test/accent-box.js -t [ babelify --presets [ es2015 ] ]

The build fails with the following error

Error: Cannot find module './util/ensure.js' from '/Users/JuanCaicedo/code/speaking/quixote-browserify/node_modules/quixote/dist'
    at /Users/JuanCaicedo/code/speaking/quixote-browserify/node_modules/browserify/node_modules/browser-resolve/node_modules/resolve/lib/async.js:55:21
    at load (/Users/JuanCaicedo/code/speaking/quixote-browserify/node_modules/browserify/node_modules/browser-resolve/node_modules/resolve/lib/async.js:69:43)
    at onex (/Users/JuanCaicedo/code/speaking/quixote-browserify/node_modules/browserify/node_modules/browser-resolve/node_modules/resolve/lib/async.js:92:31)
    at /Users/JuanCaicedo/code/speaking/quixote-browserify/node_modules/browserify/node_modules/browser-resolve/node_modules/resolve/lib/async.js:22:47
    at FSReqWrap.oncomplete (fs.js:82:15)

That makes me think it's a problem with how the quixote module is built?

bendrucker commented 7 years ago

That makes me think it's a problem with how the quixote module is built?

Yup, that definitely confirms it! My guess is that it's using require internally even if it's a self-contained bundle. Can't do that, it'll cause bundlers like browserify to try to find those modules.

JuanCaicedo commented 7 years ago

Perfect @bendrucker thanks!