Trying to run my node app, with node main.js
, but getting this error: Error [ERR_REQUIRE_CYCLE_MODULE]: Cannot require() ES Module
. I have also tried node --experimental-specifier-resolution=node main.js
.
My main.js
file imports things from './schema/index.js'
using regular esm syntax, like: import { importName } from './schema/index.js'
. I am not using require, so not sure why it’s accusing me of that.
Full error shown below.
What am I doing wrong here?
→ node main.js
node:internal/modules/esm/loader:315
throw new ERR_REQUIRE_CYCLE_MODULE(message);
^
Error [ERR_REQUIRE_CYCLE_MODULE]: Cannot require() ES Module /path/to/app/schema/index.js in a cycle. (from /path/to/app/noop.js)
at ModuleLoader.importSyncForRequire (node:internal/modules/esm/loader:315:15)
at loadESMFromCJS (node:internal/modules/cjs/loader:1414:24)
at Module._compile (node:internal/modules/cjs/loader:1547:5)
at Object..js (node:internal/modules/cjs/loader:1677:16)
at Module.load (node:internal/modules/cjs/loader:1318:32)
at Function._load (node:internal/modules/cjs/loader:1128:12)
at TracingChannel.traceSync (node:diagnostics_channel:322:14)
at wrapModuleLoad (node:internal/modules/cjs/loader:219:24)
at Module.require (node:internal/modules/cjs/loader:1340:12)
at require (node:internal/modules/helpers:138:16) {
code: 'ERR_REQUIRE_CYCLE_MODULE'
}
Node.js v22.12.0
PS. There is no file called noop.js
, and I have no idea what that part means!! Has anyone seen this before?
package.json:
{
"name": "writing-api-subgraph-storybook",
"version": "0.0.1",
"dependencies": {},
"packageManager": "[email protected]",
"module": "./main.js",
"type": "module",
"main": "./main.js"
}