Starting last Friday I'm suddenly getting ERR_REQUIRE_ESM errors when trying to run Backstage on my local machine. I'm not entirely sure what changed, as far as I can tell this worked just fine before. What's even more interesting is that the error seems to be coming from different backend modules. Any ideas of what I could try to diagnose what's going wrong?
#Getting ERR_REQUIRE_ESM errors all of a sudden
21 messages Β· Page 1 of 1 (latest)
I've seen this happen when backend plugin tries to import something from a frontend plugin π€
This is one of the errors I'm seeing:
/Users/jmezach/Code/rr/Backstage/node_modules/@backstage-community/plugin-announcements-backend/dist/router.cjs.js:121
actionType: pluginAnnouncementsCommon.AUDITOR_ACTION_DELETE,
^
Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/jmezach/Code/rr/Backstage/node_modules/@backstage-community/plugin-announcements-backend/node_modules/uuid/dist-node/index.js from /Users/jmezach/Code/rr/Backstage/node_modules/@backstage-community/plugin-announcements-backend/dist/router.cjs.js not supported.
Instead change the require of index.js in /Users/jmezach/Code/rr/Backstage/node_modules/@backstage-community/plugin-announcements-backend/dist/router.cjs.js to a dynamic import() which is available in all CommonJS modules.
at Object.newLoader [as .js] (/Users/jmezach/Code/rr/Backstage/node_modules/pirates/lib/index.js:121:7)
at Object.<anonymous> (/Users/jmezach/Code/rr/Backstage/node_modules/@backstage-community/plugin-announcements-backend/dist/router.cjs.js:7:12)
at Object.newLoader [as .js] (/Users/jmezach/Code/rr/Backstage/node_modules/pirates/lib/index.js:121:7) {
code: 'ERR_REQUIRE_ESM'
}
This seems to import something from the common package into the backend plugin, which should be fine right?
Hmm, maybe I'm being hit by this? https://github.com/uuidjs/uuid/releases/tag/v13.0.0
Turns out I needed to update to Node 22 to make this work properly
We actually have on our radar that 20 is EOL now, and we should be supporting 22 + 24.
Missed that in the last mainline last week, but we're looking at making the switch in the next mainline.
@slim marten Thanks for the update. Upgrading to Node 22 was fairly painless to be honest. I just used nvm to switch to Node 22 and it worked like a charm. Also updated the Dockerfile to use Node 22 base images and that also worked just fine.
π good to know. We have a PR ready to ship soonish that switches to node 22 minimum https://github.com/backstage/backstage/pull/31454 but some tests are failing there currently. Hopefully will get some time to get that across the line before the next mainline.
GitHub
Hey, I just made a Pull Request!
Following our Version Policy for Node this updates to add support for Node 22 to 24 in CI. It also updated the @types/node version where used.
Node 24 will become a...
hey im hitting this as well but we're already on node 22
the uuid update in announcements and playlists i believe getting the same exact error
actually.. sorry resolved the above but still get:
[backend]: throw e;
[backend]: ^
[backend]:
[backend]: Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './v4' is not defined by "exports" in /app/node_modules/uuid/package.json
[backend]: at exportsNotFound (node:internal/modules/esm/resolve:296:10)
[backend]: at packageExportsResolve (node:internal/modules/esm/resolve:643:9)
[backend]: at resolveExports (node:internal/modules/cjs/loader:640:36)
[backend]: at Module._findPath (node:internal/modules/cjs/loader:748:31)
[backend]: at Module._resolveFilename (node:internal/modules/cjs/loader:1235:27)
[backend]: at Module._load (node:internal/modules/cjs/loader:1075:27)
[backend]: at TracingChannel.traceSync (node:diagnostics_channel:315:14)
[backend]: at wrapModuleLoad (node:internal/modules/cjs/loader:218:24)
[backend]: at Module.require (node:internal/modules/cjs/loader:1340:12)
[backend]: at require (node:internal/modules/helpers:141:16) {
[backend]: code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
[backend]: }
[backend]:
[backend]: Node.js v22.11.0```
its coming from
ββ @backstage/backend-common@npm:0.23.3
β ββ @kubernetes/client-node@npm:0.20.0 (via npm:0.20.0)
β
ββ @backstage/backend-common@npm:0.24.1
β ββ @kubernetes/client-node@npm:0.20.0 (via npm:0.20.0)
β
ββ @backstage/backend-common@npm:0.25.0
β ββ @kubernetes/client-node@npm:0.20.0 (via npm:0.20.0)
β
ββ @backstage/backend-common@npm:0.24.1 [32d6d]
β ββ @kubernetes/client-node@npm:0.20.0 (via npm:0.20.0)
β
ββ @backstage/backend-common@npm:0.25.0 [3fad9]
β ββ @kubernetes/client-node@npm:0.20.0 (via npm:0.20.0)
β
ββ @backstage/backend-common@npm:0.24.1 [6fc4f]
β ββ @kubernetes/client-node@npm:0.20.0 (via npm:0.20.0)
β
ββ @backstage/backend-common@npm:0.23.3 [d1250]
ββ @kubernetes/client-node@npm:0.20.0 (via npm:0.20.0)```
forcing 1.4.0 lets back back around to an ESM issue: [backend]: /app/node_modules/@backstage/backend-common/dist/index.cjs.js:121 [backend]: function readHttpListenOptions(config) { [backend]: ^ [backend]: [backend]: Error [ERR_REQUIRE_ESM]: require() of ES Module /app/node_modules/@kubernetes/client-node/dist/index.js from /app/node_modules/@backstage/backend-common/dist/index.cjs.js not supported. [backend]: Instead change the require of index.js in /app/node_modules/@backstage/backend-common/dist/index.cjs.js to a dynamic import() which is available in all CommonJS modules. [backend]: at Object.newLoader [as .js] (/app/node_modules/pirates/lib/index.js:121:7) [backend]: at TracingChannel.traceSync (node:diagnostics_channel:315:14) [backend]: at Object.<anonymous> (/app/node_modules/@backstage/backend-common/dist/index.cjs.js:56:18) { [backend]: code: 'ERR_REQUIRE_ESM' [backend]: } [backend]: [backend]: Node.js v22.11.0 [app]: Loaded config from app-config.yaml [app]: fatal: not a git repository (or any of the parent directories): .git [app]: fatal: not a git repository (or any of the parent directories): .git [app]: NOTE: Did not compute git version or commit hash, could not execute the git command line utility [app]: <i> [webpack-dev-server] Project is running at: [app]: <i> [webpack-dev-server] Loopback: http://127.0.0.1:3000/ [app]: <i> [webpack-dev-server] Content not from webpack is served from '/app/packages/app/public' directory [app]: <i> [webpack-dev-server] 404s will fallback to '/index.html' [app]: Rspack compiled successfully
following up it seems that it starts up on node 22.21.1 but this error is on node 22.11.0 -- will confirm by upgrading our node to newer 22.x and follow up just for completeness.
confirming that fixed it
Hello All, facing this ERR_REQUIRE_ESM and if I specify uuid version then get this package export errors, when upgraded announcement & lingustic backend plugin. We are also on node 22.11.0. So can you confirm which node version fixed these errors ?
I believe you need to be on 22.18 or newer but don't quote me on that