fix: use pathToFileURL for dynamic import on Windows#12
Conversation
On Windows, resolve() returns paths like C:\Users\...\server\index.mjs, but Node.js ESM loader requires file:// URLs for dynamic imports. Using pathToFileURL(entryPath).href converts the absolute path to a proper file URL, fixing ERR_UNSUPPORTED_ESM_URL_SCHEME on Windows. Co-Authored-By: Wankong <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe PR updates the build script to use ChangesBuild and Module Loading Improvements
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
rimraf替代rm命令,保证可以在windows环境中正常build。npx usage-board@latest时报ERR_UNSUPPORTED_ESM_URL_SCHEME错误的问题。根因:
src/index.ts中loadNitroEntrypoint函数使用resolve()获取绝对路径后直接传给import()。在 Windows 上resolve()返回C:\Users\...\server\index.mjs形式的路径,但 Node.js ESM loader 要求动态import()必须使用file://URL scheme。修复: 使用 Node.js 内置的
pathToFileURL()将绝对路径转为file://URL,兼容所有平台。pathToFileURL产生file:///path/to/file,行为不变pathToFileURL产生file:///C:/Users/.../file,ESM loader 可正确加载Summary by CodeRabbit