Transpile node_modules like create-react-app #915
-
Hello, However, there is one significant difference related to browser compatibility. Create-react-app applies babel-preset-env even to node_modules to address this issue, as seen in this PR. In rsbuild, as far as I know, only the application source is transpiled with swc by default. Of course, it's possible to add modules to include for transpilation, but this is almost impossible if you need to support slightly older browsers. So, we are currently adding all of node_modules to include. (Of course, as stated in the document, this is not a recommended approach) Although rsbuild is not a tool meant to replace create-react-app, it would be great if related features could be added. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Thanks for your feedback! Whether to compile node_modules is a frequently discussed issue. It can provide better compatibility but sacrifices build performance since most dependencies do not require secondary compilation. Most modern frameoworks do not transpile node_modules by default, Next.js provides transpilePackages to manually control this. With Rsbuild, we provide include to transpile dependencies and Check Syntax Plugin to automatically detect syntax issues. This is what we currently recommend. For CRA projects, how about adding some notes to the CRA migrate guide? If the project needs to be consistent with CRA's behavior, it can manually add include node_modules. |
Beta Was this translation helpful? Give feedback.
-
Thank you for your response! I wasn't aware of the Check Syntax Plugin, but it seems like it could be a solution to the problem. This document advises against transpiling all node_modules. Therefore, rather than suggesting to include node_module in the CRA guide, it might be better to specify the method of using the Check Syntax Plugin! |
Beta Was this translation helpful? Give feedback.
Thanks for your feedback!
Whether to compile node_modules is a frequently discussed issue. It can provide better compatibility but sacrifices build performance since most dependencies do not require secondary compilation.
Most modern frameoworks do not transpile node_modules by default, Next.js provides transpilePackages to manually control this.
With Rsbuild, we provide include to transpile dependencies and Check Syntax Plugin to automatically detect syntax issues. This is what we currently recommend.
For CRA projects, how about adding some notes to the CRA migrate guide? If the project needs to be consistent with CRA's behavior, it can manually add include node_modules.