#[ERR_REQUIRE_ESM] on a fresh install of wrangler

14 messages · Page 1 of 1 (latest)

elder mulch
#

Hi, I used npm create cloudflare@latest to setup a basic js Worker project.
Upon swapping the hello world template's index.js, when running the project I ran into the following issue:

Error [ERR_REQUIRE_ESM]: require() of ES Module [...]\node_modules\youch\build\index.js from [...]\node_modules\miniflare\dist\src\index.js not supported.
Instead change the require of [...]\node_modules\youch\build\index.js in [...]\node_modules\miniflare\dist\src\index.js to a dynamic import() which is available in all CommonJS modules.
    at handlePrettyErrorRequest ([...]\node_modules\miniflare\dist\src\index.js:70941:21)
    at async #handleLoopback ([...]\node_modules\miniflare\dist\src\index.js:81676:20)

the file, with only the following (original script has more but just this is enough to cause the issue):

export default {
 async fetch(req) {

  const repo = "example/Repository"

  const releases = await fetch(
   `https://api.github.com/repos/${repo}/releases`
  ).then(r => r.json())
  return new Response('Hello World!');
 }
}

causes this. I changed nothing in any other file than index.js. Nothing online about people having the issue for specifically youch and miniflare. There is one post on this discord about it, but no one answered it. https://discord.com/channels/595317990191398933/1415375932616872028

floral wraith
#

What node/npm version are you using?

elder mulch
#

node v20.11.1
npm 10.2.4

#

sorry for the insanely late response btw

#

i did what i wanted in the web editor, but local wrangler would still be cool

floral wraith
#

Your node version is too out of date - you'll need at least 20.19.0 for require(esm), or ideally the latest 22/24

#

Then this should work fine 😄

elder mulch
#

let me upgrade it then

#

it WORKS

#

thank you so much

#

insane to finally see this thing run locally

#

🥹

floral wraith
#

awesome! happy to help 😄