You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Reacted by ignoreswing, Travis Vander Hoop, FengNobita, Daedalus11069, Wagner Souza, Ahmed Mahmoud, leo, Guilherme Delai, Alejandro Tunaroza, param-fk and 11 more
Reacted by Mathieu, Thomas Sileghem, Jannik, ignoreswing, Travis Vander Hoop, Ahmed Mahmoud, FabianElsmer, Guilherme Delai, Alejandro Tunaroza, Eddy and 4 more
@felixfbecker, I just came across the very same issue and adding this plugin fixed it. Make sure you add the property "plugins": ["syntax-dynamic-import"] like this:
@felixfbecker Turns out you need babel-plugin-dynamic-import-node
It fixed the issue for me - run it in before you run tests.
However, It will cause Webpack to create a single bundle, so make sure you only use that plugin for tests, and not for your build.
Reacted by kontrollanten, noonipoony, Alexey Ozerov, bookmoons, Scott Dickerson, Andrii Lundiak, Mally, Jack Harrhy, Louis, jiajianrong and 3 more
Reacted by Mally, Jack Harrhy, jiajianrong and Sander Vispoel
@komali2 yep, it should. we'll need a bit more info to debug though... can you create a new issue with your configs (or even better, a small repo that repros the issue)?
I had the same problem. I tried @babel/plugin-syntax-dynamic-import and babel-plugin-dynamic-import-node but didn't work. So after a couple of hours, I found out that the problem was my 2 configuration files (.babelrc and webpack.config.js). Those configuration files were merging and the result wasn't the expected.
Solution:
Handle your webpack and babel configuration in a single file. I did it on my webpack.config.js file as follows:
The solution spotted by @jdgarcia1381 works for me, but I'd prefer to keep the .babelrc file.
Edit: I just found out why it was failing to me. it was a trailing comma I had added in the .babelrc file.
Once this is being imported in my webpack settings and parsed as a json: options: { ...JSON.parse(fs.readFileSync(path.resolve(__dirname, '../.babelrc'))), },
and my settings were defined as: "env": { "test": { "plugins" : ["dynamic-import-node"], } }
All I had to do was to search for a json error there, and it was the trailing coma, so I removed it: "env": { "test": { "plugins" : ["dynamic-import-node"] } }
Activity
loganfsmyth commentedon Jul 23, 2017
You'll need to enable https://babeljs.io/docs/plugins/syntax-dynamic-import/ The
import()syntax is still an experimental proposal, so you need to opt-in to Babel's support for it.felixfbecker commentedon Sep 8, 2017
I have enabled that plugin in .babelrc but still get the error. Any idea?
patricksmms commentedon Oct 13, 2017
@felixfbecker, I just came across the very same issue and adding this plugin fixed it. Make sure you add the property "plugins": ["syntax-dynamic-import"] like this:
digital-flowers commentedon Oct 20, 2017
@felixfbecker do you use SSR ?
christophediprima commentedon Nov 7, 2017
webpack/webpack#5123
kjda commentedon Jan 16, 2018
getting
.babelrc
dependencies:
iansawyerva commentedon Jan 18, 2018
@kjda
you have the plugin specified as "dynamic-import-webpack", its "syntax-dynamic-import"
digital-flowers commentedon Jan 19, 2018
// try this util i made to avoid issues related to dynamic imports with ssr rendering
how to use?
rommguy commentedon Feb 22, 2018
@felixfbecker Turns out you need babel-plugin-dynamic-import-node
It fixed the issue for me - run it in before you run tests.
However, It will cause Webpack to create a single bundle, so make sure you only use that plugin for tests, and not for your build.
kontrollanten commentedon Mar 10, 2018
Thanks @rommguy, it solved it for me!
dyegolara commentedon Mar 20, 2018
It got solved for me when I changed the webpack's file name from
webpack.config.jstowebpack.config.babel.jskomali2 commentedon Apr 12, 2018
I am having this issue, none of the above solutions function / are ideal.
Does webpack dynamic importing work with babel?
existentialism commentedon Apr 12, 2018
@komali2 yep, it should. we'll need a bit more info to debug though... can you create a new issue with your configs (or even better, a small repo that repros the issue)?
komali2 commentedon Apr 12, 2018
Ok, thank you, I'll create a new issue
komali2 commentedon Apr 12, 2018
@existentialism I'm not convinced I'm looking at an actual bug, so I'll stay in "support mode" for now. Here's the stack overflow question if you wanna take a crack at it: https://stackoverflow.com/questions/49788115/syntax-error-on-dynamic-import-using-webpack-and-babel
BonBonSlick commentedon Nov 11, 2018
rahmatkruniawan commentedon Jan 2, 2019
I got the same issue like @BonBonSlick , still, looking for another solution for this
jdgarcia1381 commentedon Jan 8, 2019
I had the same problem. I tried
@babel/plugin-syntax-dynamic-importandbabel-plugin-dynamic-import-nodebut didn't work. So after a couple of hours, I found out that the problem was my 2 configuration files (.babelrcandwebpack.config.js). Those configuration files were merging and the result wasn't the expected.Solution:
Handle your webpack and babel configuration in a single file. I did it on my
webpack.config.jsfile as follows:sergioviniciuss commentedon Apr 2, 2019
The solution spotted by @jdgarcia1381 works for me, but I'd prefer to keep the .babelrc file.
Edit: I just found out why it was failing to me. it was a trailing comma I had added in the .babelrc file.
Once this is being imported in my webpack settings and parsed as a json:
options: { ...JSON.parse(fs.readFileSync(path.resolve(__dirname, '../.babelrc'))), },and my settings were defined as:
"env": { "test": { "plugins" : ["dynamic-import-node"], } }All I had to do was to search for a json error there, and it was the trailing coma, so I removed it:
"env": { "test": { "plugins" : ["dynamic-import-node"] } }And now it works like a charm!
BonBonSlick commentedon Jan 20, 2020
issue still exists
webpack.dev.config
error
any babels plugins do not help