Trying to set up next.js test - slicemachine error ERR_REQUIRE_ESM

Hello,
I'm trying to get started with Prismic and I'm already running into a problem. I am following the guide to setup a project with nextjs. Everything works smoothly until I attempt to run slicemachine. It appears there is a problem in the node_modules communication between "ora" and "@slicemachine". I have tried the suggested solution of changing the filename in question to index.cjs and removing the "type: module" in the package.json. Here is the CLI readout:

You're about to configure Slicemachine... Press ctrl + C to cancel
✔ Logged in as ********
✔ Next.js detected
? Connect a Prismic Repository or create a new one Create a new Repository
ℹ The name acts as a domain/endpoint for your content repo and should be completely unique.
? Name your Prismic repository https://********
✔ We created your new repository https://********
✔ The Prismic Visual Builder was installed successfully
✔ Project configured! Ready to start
■ Run npm run slicemachine to now launch your Local Builder
********@******** ******** % npm run slicemachine

> slicemachine
> start-slicemachine

node:internal/modules/cjs/loader:1125
      throw new ERR_REQUIRE_ESM(filename, parentPath, packageJsonPath);
      ^

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /Users/********/********/nextjs/********/node_modules/ora/index.js
require() of ES modules is not supported.
require() of /Users/********/********/nextjs/********/node_modules/ora/index.js from /Users/********/********/nextjs/********/node_modules/@slicemachine/core/build/src/utils/cliLogs.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /Users/********/********/nextjs/********/node_modules/ora/package.json.

    at new NodeError (node:internal/errors:363:5)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1125:13)
    at Module.load (node:internal/modules/cjs/loader:988:32)
    at Function.Module._load (node:internal/modules/cjs/loader:828:14)
    at Module.require (node:internal/modules/cjs/loader:1012:19)
    at require (node:internal/modules/cjs/helpers:93:18)
    at Object.<anonymous> (/Users/********/********/nextjs/********/node_modules/@slicemachine/core/build/src/utils/cliLogs.js:8:31)
    at Module._compile (node:internal/modules/cjs/loader:1108:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1137:10)
    at Module.load (node:internal/modules/cjs/loader:988:32) {
  code: 'ERR_REQUIRE_ESM'
}

Please help as I would really love to use Prismic on a project.

Thanks!

Ok I was trying to investigate further and upon running "npm update" I found a discrepancy in the dependencies:

npm WARN ERESOLVE overriding peer dependency
npm WARN Found: ora@6.0.1
npm WARN node_modules/ora
npm WARN   ora@"^6.0.1" from the root project
npm WARN   1 more (slice-machine-ui)
npm WARN 
npm WARN Could not resolve dependency:
npm WARN peer ora@"^5.4.1" from @slicemachine/core@1.0.1
npm WARN node_modules/@slicemachine/core
npm WARN   @slicemachine/core@"^1.0.1" from slice-machine-ui@0.1.2
npm WARN   node_modules/slice-machine-ui

I ran npm install ora@5.4.1 and now I am able to launch the slicemachine server.

Can anyone confirm this is ok?

Thanks

Hello @jonathancdev

Welcome to the Prismic community, and thanks for reaching out to us.

To set up the Slice machine, you need at least Node.js 12.0 or later. Check this by running node -v in your terminal.

Can you also paste your package.json here? We don't need to install npm install ora@5.4.1. You might need to update npm version too. Try running npm install -g npm@latest.

Thanks,
Priyanka

I have this error but I'm running Node 16.11.0 and NPM 8.5.5

Hey @hi15, which version of Slice Machine are you using?
It shouldn’t have any issues with node 16

Hi Pau,

I don't know - I'm just following the guide when you sign up.

See - NextJS start project guide doesn't work

Which version of the prismic cli do you have in your machine?

Hi @jonathancdev

If i understand correctly, you want to update from v0.1.2 to the most recent version?

I'm new to Prismic. I was wanting to try it to see if it was suitable for a future project.

I've created an account and clicked on "Next.js project" it then gives you a guide on the right hand side to get started. I have followed those instructions perfectly and it doesn't work. Everything will be the latest version.

Hello @hi15, if you want you can send us your project code repository and the instructions to run it so we can try and see the error on our end.

This error is happening for me as well, on a fresh install with only slicemachine and an empty package.json. I've opened an issue here: Error [ERR_REQUIRE_ESM]: require() of ES Module · Issue #420 · prismicio/slice-machine · GitHub

1 Like

Hello @isak, thanks for joining the conversation and for opening the issue on Github. This helps developers better visualize use cases and track them.

1 Like

Just as a follow-up to this.

The current fix seems to be to rollback node-fetch to 2.6.1:

npm i node-fetch@2.6.1

Thanks, @dhayes for letting us know.