slice-machine
slice-machine copied to clipboard
Error [ERR_REQUIRE_ESM]: require() of ES Module
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.
Seems like the problem isn't in the actual cliLogs-file, but rather that esModuleInterop is transforming the imports into requires.
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.
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
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.
Current dirty solution is to install node-fetch v2.6.1 - npm i [email protected]
++
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)