acvetkov / sinon-chrome

Testing chrome extensions with Node.js
ISC License
437 stars 48 forks source link

Cannot import sinon-chrome with webpack #11

Closed sk- closed 8 years ago

sk- commented 8 years ago

When I try to require the new version 1.0.0 with webpack I get the following error.

TypeError: 'undefined' is not an object (evaluating 'modules[moduleId].call')
acvetkov commented 8 years ago

Hi, @sk- .

It's legendary problem =). Check out this issue in webpack repo https://github.com/webpack/webpack/issues/304

This problem is related with incorrect sinon exports module interface, you should load sinon "manually" to solve it.

sk- commented 8 years ago

I'm not sure that is the problem. I'm using version 2.0 of sinon from github and I did not have any troubles when requiring the previous version of sinon chrome with webpack. On Nov 14, 2015 5:43 AM, "Aleksey Tsvetkov" notifications@github.com wrote:

Hi.

It's legendary problem =). Check out this issue in webpack repo webpack/webpack#304 https://github.com/webpack/webpack/issues/304

This problem is related with incorrect sinon exports module interface, you should load sinon "manually" to solve it.

— Reply to this email directly or view it on GitHub https://github.com/acvetkov/sinon-chrome/issues/11#issuecomment-156670914 .

acvetkov commented 8 years ago

@sk-, Because we have bundled sinon-chrome by webpack since 1.0 version.

In version < 1.0, we have not build with resolving dependencies, only js files concatination.

I think, I can fix our webpack config to solve this problem.

But you should know, you can do it in your project webpack config. Just fix loader for sinon module.

acvetkov commented 8 years ago

@sk- Can you change your webpack config? Add rules


var path = require('path');

// ...

resolve: {
   alias: {
      sinon: path.resolve(__dirname, 'node_modules/sinon/pkg/sinon.js') // require dist version instead
   }
},
module: {
   noParse: [
      /node_modules\/sinon/ // ignore sinon module
   ]   
}

You should install sinon before, Look at my webpack.config

michalczaplinski commented 7 years ago

@acvetkov Your config almost worked for me - I had to make 2 modifications:

  1. Use the unbundled version of sinon that is insidenode_modules/sinon/libinstead ofnode_modules/sinon/pkg`
  2. Add the $ to the noParse rule. Otherwise it would also eagerly cover the sinon-chrome package itself!
var path = require('path');

// ...

resolve: {
   alias: {
      sinon: path.resolve(__dirname, 'node_modules/sinon/lib/sinon.js') // require dist version instead
   }
},
module: {
   noParse: [
      /node_modules\/sinon$/ // ignore sinon module
   ]   
}