Skip to content

fix: doctor parser error #808

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

fix: doctor parser error #808

wants to merge 3 commits into from

Conversation

hualigushi
Copy link

@hualigushi hualigushi commented Apr 22, 2025

复现仓库:https://github.com/hualigushi/react-js
问题描述:当一个文件后缀名是 js , 文件内容包含 jsx 语法时,doctor 命令会报错,但是 dev 和 build 命令均没有报错
截屏2025-04-22 14 05 55

@@ -30,6 +30,7 @@ export default async (
write: false,
// enable bundle for trigger onResolve hook, but all deps will be externalized
bundle: true,
loader: { '.js': 'jsx' },
Copy link
Member

Choose a reason for hiding this comment

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

我其实是倾向于优化报错而不是加 loader 的,毕竟 JSX 并非 JS 就应该写在 .jsx 或者 .tsx 里,显式告诉构建工具这个文件的 AST 应该用什么来解析。

但社区构建工具宽容度还是太高了,就连 React 官方文档都是 App.js 而不是 App.jsxhttps://react.dev/learn/writing-markup-with-jsx ,CRA 模板的构建配置也是一锅端的 babel 配置:https://github.com/facebook/create-react-app/blob/6254386531d263688ccfa542d0e628fbc0de0b28/packages/react-scripts/config/webpack.config.js#L417

所以我们有两个选择,顺应 or 坚持, @hualigushi @Jinbao1001 两位一起看看

Copy link
Author

Choose a reason for hiding this comment

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

用户的项目是迁移过来的,如果这样的文件很多,是提示用户一个个改吗 ?

Copy link
Author

Choose a reason for hiding this comment

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

提示用户修改文件
截屏2025-05-05 13 50 45

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.

2 participants