[CRA] dynamic Import don't work
See original GitHub issueDescribe the bug
If using dynamic import, throw error Support for the experimental syntax 'dynamicImport' isn't currently enabled. But in CRA don’t have the error.
To Reproduce Steps to reproduce the behavior:
- Create a new project with CRA and SB
- Use dynamic import
- See error
System:
- OS: [MacOS]
- Framework: CRA 2.0.5
- Version: [e.g. 4.0.4]
Issue Analytics
- State:
- Created 5 years ago
- Reactions:5
- Comments:24 (20 by maintainers)
Top Results From Across the Web
Dynamic import doesn't work with combined CRA and SSR
It works fine but in my code I have a dynamic import await import("localization/" + newLanguage + "/" + newLanguage + ".json"); and...
Read more >React dynamic imports and route-centric code splitting guide
Learn how to speed up your React apps using dynamic imports, React.lazy(), React.Suspense, React Router, and Loadable Components.
Read more >Code-Splitting - React
The React.lazy function lets you render a dynamic import as a regular component. Before: import OtherComponent from '.
Read more >CRA create react app build failure. "The target environment ...
CRA create react app build failure. "The target environment doesn't support dynamic import() syntax so it's not possible to use external type ' ......
Read more >Dynamic SVG Imports in Create-React-App | by Ryan Hutzley
You have a bunch of SVGs you want to include in your CRA. You want to avoid a gazillion import statements at the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

As a workaround, you can create
.babelrcin the.storybookdir with something like this:(Maybe some other plugins/presets will be needed)
@Hypnosphi , WYT about adding this by default ? looks like CRA uses it
Came across this today - took some digging, but eventually found a solution.
The bug is actually in webpack, which storybook uses.
It is this: https://github.com/webpack/webpack/issues/8656
The solution is to install the correct version of
acornMaybe worth doing the whole
rm -rf node_modules && rm package-lock.jsonthing as well.For completeness, here is the .babelrc file that worked with our project:
.babelrc
and relevant devdeps from
package.json: