-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Issues creating WebPack Chunks and React LazyLoading #10273
Comments
Hey @mustik22! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly. If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite. |
Why are you transpiling modules to commonjs? You should let webpack handle them, so that it can properly split your bundle. |
As you know Webpack scripts evolve over time, approaches (and work arounds) work in one version but are left in even as the excellent babel and Webpack products evolve. That being said, when I remove that from the script, I get a significant number of errors in the log (such as) ... I am sure I added it (at the time) as a reasonable resolution to a problem that I had. Any alternative suggestions would be greatly appreciated. |
I think I'm having a similar issue. For me after I upgrade @babel/core to 7.5.5, code splitting and dynamic importing breaks. The difference for me is I just have to downgrade @babel/core to 7.5.4 in order for the problem to go away, I don't have to downgrade @babel/preset-env or @babel/register. I know that's not a whole lot to go off of, but any ideas? I'm using webpack version 4.38. |
@smparsons The OP's issue is that setting If you don't have a similar configuration, please file a new issue and attach your webpack configuration and package lock files. |
@JLHwung Actually I have modules set to commonjs in my @babel/preset-env configuration too. Just so I understand, why does that render code splitting useless? |
And why did the behavior recently change? |
In babel/preset-env 7.5, we have enabled proposal-dynamic-import transformer. If you specified Code splitting works since the transformer is not included by default before 7.5.0 It is not recommended to use {
presets: [["@babel/preset-env", { modules: false }]]
} |
@JLHwung Interesting, thanks for the explanation. |
Thank you! That seems to have resolved the problem. I also changed concatenateModules: false in webpack, that got rid of most the ModuleConcatenation bailout: failures. |
Recently upgrading to the latest version of babel (7.5) has resulted in the chunk creation behavior in Webpack to change. Subsequently downgrading to @babel/preset-env to 7.4.5 and @babel/register to 7.4.5 resolved the problem. Webpack version 4.38.
Basically I am creating multiple chunks using the LazyLoading feature of react. This feature has been working very well up to this point.
In React something like ..
const { default: module } = await import(/* webpackChunkName: "Ace" */ 'react-ace')
Would create
vendors
Ace.js 1.61 MiB vendorsAce [emitted] vendors~AceThe failure is that this particular output module as well as a few others are not created, and all vendor code (node_modules) is loaded into the 'vendors~bundle.js' file.
vendors
bundle.css 575 KiB vendorsbundle [emitted] vendorsbundlebundle.js 9 MiB vendorsvendors
bundle [emitted] vendorsbundleI have isolated the issue to those two babel modules. Rebuilding the node_modules (yarn install) and then downgrading those two modules resolves the issue.
Relevent Webpack configuration
(happy to provide the full file)
output: {
path: DIST_DIR,
filename: 'bundle.js', // Single file node
chunkFilename: '[name].js',
publicPath: '/dist/', // for 'Hot' Module Replacement (HMR), images
},
There is a similar config for JSX files ...
{
test: /.js?$/,
exclude: /node_modules/,
exclude: /geoLocation.js$/,
loader: 'babel-loader',
query: {
presets: [
.babelrc
{
"presets": ["@babel/preset-env", "@babel/preset-react"]
"plugins": ["@babel/plugin-syntax-dynamic-import"]
}
Package.json
Can be provided, but it only displays the target versions, not the actual. I got the actual versions from the yarn.lock file (included).
Environment
Mac OS
Visual Studio Code C#, React
Possible Solution
Downgrade @babel/preset-env to 7.4.5 and @babel/register to 7.4.5
Thank you in advance.
yarn.lock.zip
The text was updated successfully, but these errors were encountered: