Skip to content
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

Merged
merged 10 commits into from
Feb 20, 2023
Merged

Conversation

luhc228
Copy link
Collaborator

@luhc228 luhc228 commented Feb 16, 2023

预打包依赖过程,由于预打包依赖的格式是 cjs,如果依赖中的依赖是被 external 的,那么预构建产物中将会是 require('xxx')。Server Bundle 如果是在 ESM 下运行的话,就会直接报错

evanw/esbuild#1921 (comment)

@luhc228 luhc228 changed the title [WIP] fix: prebundle esm module error fix: prebundle esm module error Feb 17, 2023
// export * from '...'
str.overwrite(start, end, filePath, { contentOnly: true });
}
str.overwrite(start, end, filePath, { contentOnly: true });
Copy link
Collaborator

@ClarkXia ClarkXia Feb 17, 2023

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 下的预编译暂时不支持。

Comment on lines -141 to +153
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;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个的 resolveLegacy 是会走的 main 入口吗

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ClarkXia
ClarkXia previously approved these changes Feb 17, 2023
answershuto
answershuto previously approved these changes Feb 17, 2023
@luhc228 luhc228 dismissed stale reviews from answershuto and ClarkXia via 7e38619 February 17, 2023 08:26
@ClarkXia ClarkXia merged commit 8eee4f0 into release/next Feb 20, 2023
@ClarkXia ClarkXia deleted the fix/prebundle-esm-module-error branch February 20, 2023 02:22
@ClarkXia ClarkXia mentioned this pull request Feb 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants