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.

[Bug]: Not work with esm package

See original GitHub issue

Version

27.3.1

Steps to reproduce

  1. Clone https://github.com/Jack-Works/jest-esm-bug-reproduce
  2. yarn
  3. node --experimental-vm-modules ./node_modules/jest/bin/jest.js

Expected behavior

Works normally

Actual behavior

SyntaxError: The requested module ‘lodash-unified’ does not provide an export named ‘debounce’

Additional context

If you run node src/main.js it works normally.

Environment

System:
    OS: Windows 10 10.0.19043
    CPU: (24) x64 AMD Ryzen 9 5900X 12-Core Processor
  Binaries:
    Node: 17.0.1 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.15 - C:\Program Files\nodejs\yarn.CMD
    npm: 7.20.1 - C:\Program Files\nodejs\npm.CMD
  npmPackages:
    jest: ^27.3.1 => 27.3.1

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
SimenBcommented, Jan 5, 2022

This happens since lodash-unified has a main field: https://www.runpkg.com/?lodash-unified@1.0.1/package.json#5

See https://github.com/facebook/jest/issues/9771#issuecomment-946052045 (it’s breaking to ignore main). This issue should be fixed in Jest 28 (whenever I have the time and energy to work on it).


web-vitals uses module which jest doesn’t (and won’t) support. They should use exports. Node cannot load it as ESM either

// file.mjs
import {getCLS} from 'web-vitals'
$ file:///Users/simen/repos/jest-esm-bug-reproduce/file.mjs:1
import {getCLS} from 'web-vitals'
        ^^^^^^
SyntaxError: Named export 'getCLS' not found. The requested module 'web-vitals' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'web-vitals';
const {getCLS} = pkg;

    at ModuleJob._instantiate (node:internal/modules/esm/module_job:124:21)
    at async ModuleJob.run (node:internal/modules/esm/module_job:181:5)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:281:24)
    at async loadESM (node:internal/process/esm_loader:88:5)
    at async handleMainPromise (node:internal/modules/run_main:65:12)
0reactions
github-actions[bot]commented, Feb 5, 2022

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

got Error [ERR_REQUIRE_ESM]: require() of ES Module not ...
The got error "[ERR_REQUIRE_ESM]: require() of ES Module not supported" occurs because the got package has been converted to be an ESM only...
Read more >
node.js - How would you fix an 'ERR_REQUIRE_ESM' error?
The latest version of Chalk is only compatible with ESM modules and thus wants you to load it with import , not require()...
Read more >
ECMAScript modules | Node.js v19.3.0 Documentation
ECMAScript modules are the official standard format to package JavaScript code for ... Resolving relative specifiers does not work because data: is not...
Read more >
ECMAScript Modules - Jest
Since ESM evaluates static import statements before looking at the code, the hoisting of jest.mock calls that happens in CJS won't work for...
Read more >
Publish ESM and CJS in a single package - Anthony Fu
Error [ERR_REQUIRE_ESM]: require() of ES Module esm-only-package not ... In some case it might work, but generally I won't think this to be ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

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