Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using Sinon with Webpack and Babel fails on import #830

Closed
ngerritsen opened this issue Sep 8, 2015 · 26 comments
Closed

Using Sinon with Webpack and Babel fails on import #830

ngerritsen opened this issue Sep 8, 2015 · 26 comments

Comments

@ngerritsen
Copy link

When trying to import sinon in a test with "import sinon from 'sinon'" or "var sinon = require('sinon')". I get the following error:

TypeError: 'undefined' is not an object (evaluating 'modules[moduleId].call')

Now sinon is unusable in ES6 projects. Is it possible to fix this?

var sinon = require('sinon');

@mroderick
Copy link
Member

Are you using sinon from npm? Which version?

@billturner
Copy link

This webpack issue covers the same thing, without a solid solution and lots of working around the problem: webpack/webpack#304. It's not the exact same error, but basically the same problem.

@ngerritsen
Copy link
Author

Yes I am using the latest npm version.

@mroderick
Copy link
Member

Yes I am using the latest npm version.

Just for the sake of history, it would be great if you could provide the version number. Future readers of this thread would then know which version you were talking about.

@mroderick
Copy link
Member

This webpack issue covers the same thing, without a solid solution and lots of working around the problem: webpack/webpack#304. It's not the exact same error, but basically the same problem.

Yeah, it looks like the module-mess in Sinon is getting to be more and more of an issue. I've taken a few attempts at rewriting it for CommonJS, but things are complicated. Pull requests welcome :)

@mroderick
Copy link
Member

I've created a ticket for the work of getting the source ported to CommonJS #834, which will most likely obviate this issue.

@grassator
Copy link
Contributor

I think this issue is solved now in the master with #850

@Robertmw
Copy link

Any updates on this? #850 doesn't solve the problem.

PS: I'm using v1.17.0

@grassator
Copy link
Contributor

@Robertmw you can try pointing sinon to git in your package.json to get the latest master and see if that helps

@Robertmw
Copy link

@grassator I tried with the below git from webpack/webpack#304 (comment) but I'll try it with the original git right away.

devDependencies: {
     "sinon": "git+https://github.com/uberVU/Sinon.JS"
 }

@ingro
Copy link

ingro commented Oct 16, 2015

@grassator I can confirm that point the dependency on my package.json to:

"sinon": "git+https://github.com/sinonjs/sinon.git"

solves my problems with Webpack.

@tusharmath
Copy link

I am also facing the same issue. For now, I am using require('sinon') before I initialize babel.

@fatso83
Copy link
Contributor

fatso83 commented Nov 6, 2015

@tusharmath : have you tried using the version hosted on GitHub as mentioned above? Fixes for this is going into version 2, which is yet to be published. This is unlikely to be fixed in the 1.x branch.

@mgrandrath
Copy link

@fatso83 I can confirm that using master fixes the issue. Sorry to hear that the fix won't make it into 1.x.

@mroderick
Copy link
Member

2.0 release should happen soon, so nothing to be sad about

@frank-weindel
Copy link

I've had a project relying on the sinon-2.0 branch (git://github.com/cjohansen/Sinon.JS.git#sinon-2.0). This has been working great up until I tried it today. The branch seems to have vanished. Is there a suitable replacement for this branch yet?

@fatso83
Copy link
Contributor

fatso83 commented Nov 24, 2015

@frank-weindel : The master branch is what is effectively becoming 2.0, so you could just as well point to that. A pre-release of 2.0 should be on NPM in a few days.

@fatso83
Copy link
Contributor

fatso83 commented Feb 10, 2016

PS. You can get the pre-release of 2.0 by doing npm install sinon@next

mlawrie added a commit to mlawrie/sticky-board that referenced this issue May 18, 2016
mlawrie added a commit to mlawrie/sticky-board that referenced this issue May 18, 2016
@junosuarez
Copy link

any update on when sinon 2 will be @latest instead of @next?

@fatso83
Copy link
Contributor

fatso83 commented Jun 9, 2016

We need help to get Sinon 2 out the door. See #991 and #1000 (and related issues) for remaining big issues if you can spare some time in helping us out.

@jonnyreeves
Copy link
Contributor

Note #966 tracks the outstanding tasks required for shipping Sinon 2.0 which uses CommonJS modules internally - help very much appreciated in getting it out the door.

@PascalSenn
Copy link

try to use it as a webpack plugin

...
plugins: [
        new webpack.ProvidePlugin( {
          'sinon': 'sinon'
       })
      ],
...

@rafaeleyng
Copy link

Just for the record, using it as with webpack.ProvidePlugin doesn't work either.

@ngerritsen
Copy link
Author

Personally I just stopped using Karma and thus not needing Webpack for unit tests. The makes them way faster to run also. Does this issue still exist? Other wise we can close it.

@junosuarez
Copy link

The issue still exists in sinon < 2.0, which is still not officially released. I recommend closing this issue either with a fix or when sinon 2.0 ships.

@fatso83
Copy link
Contributor

fatso83 commented Feb 1, 2017

This works in Sinon 2.0 and the README has since long had a BIG FAT WARNING that bundlers like WebPack do not work with Sinon 1.x. If you need to bundle, use one of the pre-release versions of Sinon. Closing this.

@fatso83 fatso83 closed this as completed Feb 1, 2017
@sinonjs sinonjs locked and limited conversation to collaborators Feb 1, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests