require() of ES Module not supported.

See original GitHub issue

Describe the bug

image

There might be a way around this that I’m just not familiar with, but vitest appears to fail when any of your node dependencies use require, which I feel is untenable.

Reproduction

Importing Adaptable in any class and then running a test which tests this class.

System Info

System:
    OS: Windows 10 10.0.19042
    CPU: (12) x64 Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz
    Memory: 13.22 GB / 31.71 GB
  Binaries:
    Node: 16.13.0 - C:\Program Files\nodejs\node.EXE
    npm: 8.1.0 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Chrome: 97.0.4692.71
    Edge: Spartan (44.19041.1266.0), Chromium (97.0.1072.62)
    Internet Explorer: 11.0.19041.1202
  npmPackages:
    @vitejs/plugin-react-refresh: ^1.3.6 => 1.3.6
    vite: ^2.7.2 => 2.7.12
    vitest: ^0.1.18 => 0.1.18

Used Package Manager

npm

Validations

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Demivancommented, Jan 26, 2022

I have checked is briefly. Not sure what is wrong in this particular case but @adaptabletools/adaptable package is just really messed up. Both main and typings fields are incorrect in package.json. Library is in CommonJs format and imports from ESM package using require. https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c - here is the explanation why ESM packages cannot be required. So I can only assume there is something wrong with their build.

0reactions
sheremet-vacommented, Jan 26, 2022

Not sure what is wrong in this particular case but @adaptabletools/adaptable package is just really messed up.

Yes, their Adaptable.js is CJS module that uses require to load ESM module, which is not supported by native Node.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error [ERR_REQUIRE_ESM]: require() of ES Module not ...
The node-fetch latest version doesn't use the require() syntax to import the package. You need to go to your package.json and type
Read more >
Error [ERR_REQUIRE_ESM]: require() of ES Module not ...
The error [ERR_REQUIRE_ESM]: require() of ES Module not supported. Instead change the require of index.js to a dynamic import() which is available in...
Read more >
require() of ES modules is not supported · Issue #43833 - GitHub
angular\compiler-cli\bundles\index.js require() of ES modules is not supported. When I try to run Jest test I get:
Read more >
require() of es module is not supported - You.com - You.com
The current version of node-fetch is ONLY compatible with an ESM import (using import ), not from CommonJS modules using require() . You...
Read more >
ECMAScript modules | Node.js v19.3.0 Documentation
Using require to load an ES module is not supported because ES modules have asynchronous execution. Instead, use import() to load an ES...
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