question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ESM Problems with Jest@26 and Node.js 14.x

See original GitHub issue

Hi, I’m using jest to test my project. Trying to test a file where I import uuid results with an error:

 ● Test suite failed to run

    SyntaxError: The requested module 'uuid' does not provide an export named 'v1'

          at async Promise.all (index 0)
      at jasmine2 (node_modules/jest-jasmine2/build/index.js:228:5)

I saw @dps910 comment and I guess it’s something similar. I’m using UUID@8, node@14 and Jest@26 (and it’s freshly-supported esm modules implementation).

Jest command: node --experimental-vm-modules .\node_modules\jest\bin\jest.js The file that I’m testing imports uuid like you suggested:

import { v1 as uuidv1 } from 'uuid';
uuidv1();

It fails only when I’m testing though.

_Originally posted by @Tzahile in https://github.com/uuidjs/uuid/issues/245#issuecomment-628650062_

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

59reactions
pl12133commented, Apr 28, 2022

My workaround for this was to manually map the uuid module to it’s commonJS export:

// jest.config.js
moduleNameMapper: {
    // Force module uuid to resolve with the CJS entry point, because Jest does not support package.json.exports. See https://github.com/uuidjs/uuid/issues/451
    "uuid": require.resolve('uuid'),
},

EDIT: This might not work depending on your projects dependency structure. See https://github.com/microsoft/accessibility-insights-web/pull/5421#issuecomment-1109168149 for a much better explanation.

This works and is more scoped than overriding exports conditions, but has the downside that it is essentially a silent yarn resolution; it forces every dependency chain through uuid to use whatever version of uuid happens to be hoisted, even if some chains want older versions.

6reactions
ctavancommented, Aug 5, 2022

I have released uuid@9.0.0-beta.0 that should restore compatibility with Jest. Please try it out and let me know if it fixes the Jest interoperability (to be tested with jest@29.0.0-alpha.1).

Read more comments on GitHub >

github_iconTop Results From Across the Web

ESM Problems with Jest@26 and Node.js 14.x - Bountysource
Hi, I'm using jest to test my project. Trying to test a file where I import uuid results with an error: ○ Test...
Read more >
Node v13 / Jest / ES6 — native support for modules without ...
Yes, it is possible from jest@25.4.0 . From this version, there is a native support of esm, so you will not have to...
Read more >
ECMAScript modules | Node.js v19.3.0 Documentation
When importing CommonJS modules, the module.exports object is provided as the default export. Named exports may be available, provided by static analysis as...
Read more >
jest monorepo cannot find module - Paddle Tennis Roma
js - /monorepo/node_modules/eslint-plugin-import/lib/rules/no-unresolved. exports ... we can use the exact same array as what we have in our webpack. js ESM ...
Read more >
ts-node - npm
TypeScript execution and REPL for node.js, with source map and native ESM support. The latest documentation can also be found on our ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found