uuidjs/uuid

ESM version exposed to environments that don't support ESM (e.g. jest 28)

simon-paris opened this issue · 1 comments

Describe the bug

The package.json exports field declares that for envrionments other than node, only the ESM version of the library can be used. The CJS version of this library is exposed to node, but not to browsers.

Jest v28 with jsdom will honour exports, but does not babelize files in node_modules. Therefore it will crash if you import this library.

  "exports": {
    ".": {
      "default": "./dist/esm-browser/index.js"
    },
  },

How to reproduce

Run this script:

# install jest and uuid
yarn add jest jest-environment-jsdom uuid

# create test scenario
cat << TESTFILE > ./tests.spec.js
test("should import uuid without crashing", () => require("uuid"));
TESTFILE

yarn jest --env jsdom

Expected behavior

non-nodejs CJS code that imports uuid should receive the CJS version of the library.

Runtime

  • OS: macOS
  • Runtime: anything other than node that honours package.json exports but doesn't have ESM support enabled e.g. jest 28
  • Runtime Version: [e.g. 14.2.0]

Additional information

[Any other information or comments that you think will help]

Duplicate of #616, right? (If not, please comment why and I'll reopen.)