egg4不支持esm语法
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 45/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- node.js, typescript
- Domain
- backend
Research direction
Start with the failing config/plugin.ts entry shown in the log, then read @eggjs/core/src/utils/index.ts and @eggjs/core/src/loader/egg_loader.ts around loadFile and readPluginConfigs. Reproduce the failure with npm run dev using the reported Node v20 setup. Done means Egg 4 can load the reported ESM configuration without the exports error.
Written by the indexing model from the issue text.
Description
详细日志如下
bash-5.1$ npm run dev
> [email protected] dev
> egg-bin dev
oclif:main process.execPath: /Users/macbookpro/.nvm/versions/node/v20.17.0/bin/node +0ms
oclif:main process.execArgv: +0ms
oclif:main process.argv: [
oclif:main '/Users/macbookpro/.nvm/versions/node/v20.17.0/bin/node',
oclif:main '/Users/macbookpro/Documents/zmn/zmn-bff-amislc-api/node_modules/.bin/egg-bin',
oclif:main 'dev'
oclif:main ] +0ms
oclif:find-root:root-plugin Finding root plugin using /Users/macbookpro/Documents/zmn/zmn-bff-amislc-api/node_modules/@eggjs/bin/bin/run.js +0ms
oclif:find-root:root-plugin Finding root starting at /Users/macbookpro/Documents/zmn/zmn-bff-amislc-api/node_modules/@eggjs/bin/bin/run.js +0ms
oclif:find-root:root-plugin Checking /Users/macbookpro/Documents/zmn/zmn-bff-amislc-api/node_modules/@eggjs/bin/bin/package.json +1ms
oclif:find-root:root-plugin Checking /Users/macbookpro/Documents/zmn/zmn-bff-amislc-api/node_modules/@eggjs/bin/package.json +0ms
oclif:find-root:root-plugin Found root by traversing up from starting point! +0ms
oclif:find-root:root-plugin Found root at /Users/macbookpro/Documents/zmn/zmn-bff-amislc-api/node_modules/@eggjs/bin +0ms
oclif:config loading core plugin from /Users/macbookpro/Documents/zmn/zmn-bff-amislc-api/node_modules/@eggjs/bin +0ms
oclif:read-pjson found oclif config in /Users/macbookpro/Documents/zmn/zmn-bff-amislc-api/node_modules/@eggjs/bin/package.json +0ms
oclif:config:@eggjs/bin command discovery options {
globPatterns: [
'**/*.+(js|cjs|mjs|ts|tsx|mts|cts)',
'!**/*.+(d.ts|test.ts|test.js|spec.ts|spec.js|d.mts|d.cts)?(x)'
],
strategy: 'pattern',
target: './dist/esm/commands'
} +0ms
oclif:config:ts-path Skipping typescript path lookup for /Users/macbookpro/Documents/zmn/zmn-bff-amislc-api/node_modules/@eggjs/bin because NODE_ENV is NOT "test" or "development" +0ms
oclif:config:@eggjs/bin loading IDs from /Users/macbookpro/Documents/zmn/zmn-bff-amislc-api/node_modules/@eggjs/bin/dist/esm/commands +1ms
oclif:config:@eggjs/bin found commands [ 'cov', 'dev', 'test' ] +6ms
oclif:config:@eggjs/bin (import) /Users/macbookpro/Documents/zmn/zmn-bff-amislc-api/node_modules/@eggjs/bin/dist/esm/commands/dev.js +24ms
oclif:config:@eggjs/bin (import) /Users/macbookpro/Documents/zmn/zmn-bff-amislc-api/node_modules/@eggjs/bin/dist/esm/commands/test.js +0ms
oclif:config:@eggjs/bin (import) /Users/macbookpro/Documents/zmn/zmn-bff-amislc-api/node_modules/@eggjs/bin/dist/esm/commands/cov.js +1ms
oclif:config reading user plugins pjson /Users/macbookpro/.local/share/egg-bin/package.json +45ms
oclif:config config done +1ms
oclif:config start init hook +0ms
oclif:config init hook done +1ms
oclif:config runCommand dev [] +0ms
oclif:config:@eggjs/bin (import) /Users/macbookpro/Documents/zmn/zmn-bff-amislc-api/node_modules/@eggjs/bin/dist/esm/commands/dev.js +15ms
oclif:config start prerun hook +0ms
oclif:config prerun hook done +0ms
oclif:egg-bin:dev init version: @oclif/[email protected] argv: [] +0ms
oclif:config start preparse hook +1ms
oclif:config preparse hook done +0ms
2025-04-07 16:57:33,442 INFO 62677 [master] node version v20.17.0
2025-04-07 16:57:33,443 INFO 62677 [master] egg version 4.0.10
2025-04-07 16:57:35,286 ERROR 62680 nodejs.Error: [@eggjs/core] load file: /Users/macbookpro/Documents/zmn/zmn-bff-amislc-api/config/plugin.ts, error: exports is not defined in ES module scope
at Object.loadFile (file:///Users/macbookpro/Documents/zmn/zmn-bff-amislc-api/node_modules/@eggjs/core/src/utils/index.ts:97:19)
at async AgentWorkerLoader.readPluginConfigs (file:///Users/macbookpro/Documents/zmn/zmn-bff-amislc-api/node_modules/@eggjs/core/src/loader/egg_loader.ts:590:23)
at async AgentWorkerLoader.loadAppPlugins (file:///Users/macbookpro/Documents/zmn/zmn-bff-amislc-api/node_modules/@eggjs/core/src/loader/egg_loader.ts:499:24)
at async AgentWorkerLoader.loadPlugin (file:///Users/macbookpro/Documents/zmn/zmn-bff-amislc-api/node_modules/@eggjs/core/src/loader/egg_loader.ts:438:23)
at async AgentWorkerLoader.loadConfig (file:///Users/macbookpro/Documents/zmn/zmn-bff-amislc-api/node_modules/egg/src/lib/loader/AgentWorkerLoader.ts:12:5)
at async Agent.loadConfig (file:///Users/macbookpro/Documents/zmn/zmn-bff-amislc-api/node_modules/egg/src/lib/egg.ts:191:5)
at async Agent.load (file:///Users/macbookpro/Documents/zmn/zmn-bff-amislc-api/node_modules/egg/src/lib/egg.ts:195:5)
at async file:///Users/macbookpro/Documents/zmn/zmn-bff-amislc-api/node_modules/egg/src/lib/egg.ts:179:7
at async file:///Users/macbookpro/Documents/zmn/zmn-bff-amislc-api/node_modules/@eggjs/core/src/lifecycle.ts:423:9
cause: {}
cause:
nodejs.ReferenceError: exports is not defined in ES module scope
at file:///Users/macbookpro/Documents/zmn/zmn-bff-amislc-api/config/plugin.ts:2:23
at ModuleJob.run (node:internal/modules/esm/module_job:234:25)
at async ModuleLoader.import (node:internal/modules/esm/loader:473:24)
at async importModule (file:///Users/macbookpro/Documents/zmn/zmn-bff-amislc-api/node_modules/@eggjs/utils/src/import.ts:286:11)
at async Object.loadFile (file:///Users/macbookpro/Documents/zmn/zmn-bff-amislc-api/node_modules/@eggjs/core/src/utils/index.ts:89:19)
at async AgentWorkerLoader.readPluginConfigs (file:///Users/macbookpro/Documents/zmn/zmn-bff-amislc-api/node_modules/@eggjs/core/src/loader/egg_loader.ts:590:23)
at async AgentWorkerLoader.loadAppPlugins (file:///Users/macbookpro/Documents/zmn/zmn-bff-amislc-api/node_modules/@eggjs/core/src/loader/egg_loader.ts:499:24)
at async AgentWorkerLoader.loadPlugin (file:///Users/macbookpro/Documents/zmn/zmn-bff-amislc-api/node_modules/@eggjs/core/src/loader/egg_loader.ts:438:23)
at async AgentWorkerLoader.loadConfig (file:///Users/macbookpro/Documents/zmn/zmn-bff-amislc-api/node_modules/egg/src/lib/loader/AgentWorkerLoader.ts:12:5)
at async Agent.loadConfig (file:///Users/macbookpro/Documents/zmn/zmn-bff-amislc-api/node_modules/egg/src/lib/egg.ts:191:5)
pid: 62680
hostname: macbooks-MacBook-Pro.local
2025-04-07 16:57:35,288 ERROR 62680 [agent_worker] start error, exiting with code:1
2025-04-07 16:57:35,313 ERROR 62677 nodejs.AgentWorkerDiedError: [master] agent_worker#1:62680 died (code: 0, signal: null)
at Master.onAgentExit (file:///Users/macbookpro/Documents/zmn/zmn-bff-amislc-api/node_modules/@eggjs/cluster/src/master.ts:338:17)
at Master.emit (node:events:519:28)
at Master.emit (node:domain:488:12)
at Messenger.sendToMaster (file:///Users/macbookpro/Documents/zmn/zmn-bff-amislc-api/node_modules/@eggjs/cluster/src/utils/messenger.ts:165:18)
at Messenger.send (file:///Users/macbookpro/Documents/zmn/zmn-bff-amislc-api/node_modules/@eggjs/cluster/src/utils/messenger.ts:129:12)
at ChildProcess.<anonymous> (file:///Users/macbookpro/Documents/zmn/zmn-bff-amislc-api/node_modules/@eggjs/cluster/src/utils/mode/impl/process/agent.ts:94:22)
at Object.onceWrapper (node:events:634:26)
at ChildProcess.emit (node:events:519:28)
at ChildProcess.emit (node:domain:488:12)
at Process.ChildProcess._handle.onexit (node:internal/child_process:294:12)
name: "AgentWorkerDiedError"
pid: 62677
hostname: macbooks-MacBook-Pro.local
2025-04-07 16:57:35,313 ERROR 62677 [master] agent_worker#1:62680 start fail, exiting with code:1
2025-04-07 16:57:35,313 ERROR 62677 [master] exit with code:1
oclif:config start finally hook +3s
oclif:config finally hook done +0ms
Error: /Users/macbookpro/Documents/zmn/zmn-bff-amislc-api/node_modules/@eggjs/bin/dist/scripts/start-cluster.mjs
{"baseDir":"/Users/macbookpro/Documents/zmn/zmn-bff-amislc-api","workers":1,"port":7001,"framework":"/Users/macbookpro/Do
cuments/zmn/zmn-bff-amislc-api/node_modules/egg","typescript":true,"tscompiler":"/Users/macbookpro/Documents/zmn/zmn-bff-
amislc-api/node_modules/ts-node/register/index.js"} exit with code 1
Code: 1
oclif:error Error: /Users/macbookpro/Documents/zmn/zmn-bff-amislc-api/node_modules/@eggjs/bin/dist/scripts/start-cluster.mjs {"baseDir":"/Users/macbookpro/Documents/zmn/zmn-bff-amislc-api","workers":1,"port":7001,"framework":"/Users/macbookpro/Documents/zmn/zmn-bff-amislc-api/node_modules/egg","typescript":true,"tscompiler":"/Users/macbookpro/Documents/zmn/zmn-bff-amislc-api/node_modules/ts-node/register/index.js"} exit with code 1
oclif:error at ChildProcess.<anonymous> (file://~/Documents/zmn/zmn-bff-amislc-api/node_modules/@eggjs/bin/dist/esm/baseCommand.js:351:33)
oclif:error at Object.onceWrapper (node:events:634:26)
oclif:error at ChildProcess.emit (node:events:519:28) +0ms
- Dominant language
- JavaScript
- Stars
- 219
- Forks
- 90
- PR merge metrics
- No merged PRs in 30d
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from eggjs/core
-
Port: Support custom pathToRegexpModule on app.options to master branchMay be free again @fengmk2 claimed this 621 days ago, and no pull request is open. Open
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
-
documentation
Difficulty 1/5 Under an hour Newbie friendliness 88/100
githubnext/gh-aw-workshop#4251 ·
Maintainers usually reply within 1 day
-
customer-support needs-triage Platform(Default)
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Leonxlnx/taste-skill#129 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100