Gothdo Gothdo - 1 year ago 64
Javascript Question

How can I bundle my tests which use Sinon.js using Rollup.js?

I'm using Rollup.js with plugins

to bundle my tests, which use Sinon.js. When I try to run the bundled file I get the following error:

Error: Dynamic requires are not currently supported by rollup-plugin-commonjs

Is there any workaround for this error, or do I have to use some other tool like Webpack?

Answer Source

The on the Sinon.js GitHub repository says:

Sinon.JS v1.x as source doesn't work with AMD loaders / RequireJS / Webpack / Browserify. For that you will have to use a pre-built version.

This has been resolved in Sinon v2.x; Please don't report this as a bug.

So it's not possible to bundle Sinon with neither Rollup.js nor Webpack. I think the best option is to use Sinon v2.x. You can install it using the following command:

npm install sinon@next

However, some Sinon plugins might not work with Sinon v2.x; for example sinon-chai requires Sinon >=1.4.0 <2.