-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: prebundle esm module error #5935
Conversation
// export * from '...' | ||
str.overwrite(start, end, filePath, { contentOnly: true }); | ||
} | ||
str.overwrite(start, end, filePath, { contentOnly: true }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mark:transformCjsImport 在 server 格式为 cjs,并且不希望 bundle 三方依赖的时候会用到。但框架推荐 esm 的格式,对于 cjs 下的预编译暂时不支持。
if (!resolvedEntryPoint) { | ||
resolvedEntryPoint = pkgJSON['main'] || 'index.js'; | ||
} | ||
// resolve "exports.import" field or "module" field | ||
const resolvedEntryPoint = (resolveExports(pkgJSON, entry) || resolveLegacy(pkgJSON) || 'index.js') as string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个的 resolveLegacy 是会走的 main 入口吗
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
预打包依赖过程,由于预打包依赖的格式是 cjs,如果依赖中的依赖是被 external 的,那么预构建产物中将会是 require('xxx')。Server Bundle 如果是在 ESM 下运行的话,就会直接报错
evanw/esbuild#1921 (comment)