0

We are developing a project that uses commonjs. When node-fetch is updated to v3.x, jest complains that:

import fetch, { RequestInfo, RequestInit, Response } from 'node-fetch';
SyntaxError: Cannot use import statement outside a module

npm run build succeeds.

If I use node --experimental-vm-modules node_modules/.bin/jest instead of jest, I get:

Must use import to load ES Module

I did some reading, it appears that we need to migrate our project to be an ESM as well. But it does not appear to be easy.

So the question is: when a dependency becomes pure ESM, how do we handle that in our code?

FYI, our project is: https://gitlab.com/tezgraph/tezgraph

Alireza
  • 5,421
  • 5
  • 34
  • 67
  • Does this answer your question? [Node.js plans to support import/export ES6 (ECMAScript 2015) modules](https://stackoverflow.com/questions/37132031/node-js-plans-to-support-import-export-es6-ecmascript-2015-modules) – Vojin Purić Sep 15 '21 at 07:12
  • Thanks for the link. I'll see if that helps me – Alireza Sep 15 '21 at 07:17

0 Answers0