sinonjs / fake-timers

Fake setTimeout and friends (collectively known as "timers"). Useful in your JavaScript tests. Extracted from Sinon.JS
BSD 3-Clause "New" or "Revised" License
802 stars 105 forks source link

"module" field doesn't point at a module #317

Closed 43081j closed 4 years ago

43081j commented 4 years ago

When used as an es module via the "module" property and a bundler, we get no exports.

The sources, and the commonjs output are individual exports, such as:

module.exports.install = fn;
// means:
const {install} = require('@sinonjs/fake-timers');

However, the browserify output results in an empty export:

import {install} from '@sinonjs/fake-timers';  // ERRORS
import * as timers from '@sinonjs/fake-timers'; // this is how it should be but is {} at the minute
import fakeTimers from '@sinonjs/fake-timers'; // ERRORS, no default export
timers.install; // DOESNT EXIST

the problem here seems to be that "module" in package.json should point at an ES module, but clearly doesn't. it instead points at a browserify bundle.. which is rather dated and will not work as expected in bundlers which interpret the "module" field.

mantoni commented 4 years ago

For Sinon we solved this by generating a separate esm module in the build.js script:

https://github.com/sinonjs/sinon/blob/d2b4b726529f167d908747d2173b5491794ac718/build.js#L61-L80

The module field in package.json points to this module. We'd need to the same for fake-timers to fix this.

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.