slice-machine icon indicating copy to clipboard operation
slice-machine copied to clipboard

Error [ERR_REQUIRE_ESM]: require() of ES Module

Open itzaks opened this issue 3 years ago • 7 comments

Versions

- slice-machine-ui: 0.3.3
- @nuxtjs/prismic: "alpha",

Reproduction

Add both dependencies as devDependencies and run npm/yarn run slicemachine, will yield the following error:

/node_modules/@slicemachine/core/build/src/utils/cliLogs.js:8
const ora_1 = __importDefault(require("ora"));
                              ^

Error [ERR_REQUIRE_ESM]: require() of ES Module /node_modules/ora/index.js 
from /node_modules/@slicemachine/core/build/src/utils/cliLogs.js not supported.
Instead change the require of index.js in /node_modules/@slicemachine/core/build/src/utils/cliLogs.js 
to a dynamic import() which is available in all CommonJS modules.

Proposed solution

Use import instead of require.

itzaks avatar Mar 18 '22 11:03 itzaks

Seems like the problem isn't in the actual cliLogs-file, but rather that esModuleInterop is transforming the imports into requires.

itzaks avatar Mar 18 '22 11:03 itzaks

This seems to be an issue with slice machine rather than to have anything to do with @nuxtjs/prismic. It happens on a fresh project even without Nuxt installed. Just running:

yarn init
yarn dlx @slicemachine/init
yarn run slicemachine

Yields the error above.

Error [ERR_REQUIRE_ESM]: require() of ES Module .../node_modules/ora/index.js from .../node_modules/@slicemachine/core/build/src/utils/cliLogs.js not supported.

Using the following:

yarn – 3.2.0
node – 16.14.0
slice-machine-ui – 0.3.3

I tried with npm 8.3.1 as well with no better luck.

itzaks avatar Mar 22 '22 08:03 itzaks

This is happening for me as well on a fresh project with NextJs.

yarn – 3.2.0
node – 16.14.0
slice-machine-ui – 0.3.3

Crevitus avatar Mar 23 '22 10:03 Crevitus

Just had this issue and it turns out I had added node-fetch during a previous attempt to get something else working. Removing node-fetch fixed this issue for me, so it may be worth looking into other packages you may have installed. Other than having installed node-fetch, my project was a fresh next.js + prismic setup.

Christopotamus avatar Apr 07 '22 02:04 Christopotamus

Current dirty solution is to install node-fetch v2.6.1 - npm i [email protected]

jeremytenjo avatar May 05 '22 17:05 jeremytenjo

++

Brewd3v avatar May 10 '22 17:05 Brewd3v

I was having the same issue. The solution from @jeremytenjo to install v2.6.1 worked for me.

(Using a next.js project--so the error isn't nuxt specific)

drewhayes avatar May 18 '22 14:05 drewhayes