Enable Babel syntax support for the dynamic import specification within `node_modules` such that webpack can handle the statements
See original GitHub issueIs this a bug report?
Yes
Did you try recovering your dependencies?
(Write your answer here.)
yarn -v
1.5.1
Which terms did you search for in User Guide?
experimental syntax ‘dynamicImport’
Environment
npx create-react-app --info .
Please specify the project directory:
create-react-app <project-directory>
But this is what is relevant:
node -v
v8.6.0
yarn -v
1.5.1
"react-scripts": "2.0.0-next.b2fd8db8",
"react-styleguidist": "7.0.14"
MacOS X
Steps to Reproduce
git clone https://github.com/stereobooster/async-precious.git
cd async-precious
git checkout styleguidist-bug
yarn
yarn styleguide
Expected Behavior
No error
Actual Behavior
styleguidist server
./node_modules/react-styleguidist/lib/rsg-components/Editor/EditorLoader.js
Syntax error: async-precious/node_modules/react-styleguidist/lib/rsg-components/Editor/EditorLoader.js: Support for the experimental syntax 'dynamicImport' isn't currently enabled (36:4):
34 | var _this2 = this;
35 |
> 36 | import('rsg-components/Editor/Editor').then(function (module) {
| ^
37 | _this2.setState({ editor: module.default });
38 | });
39 | }
Add @babel/plugin-syntax-dynamic-import (https://git.io/vb4Sv) to the 'plugins' section of your Babel config to enable parsing.
from thread-loader (worker 0)
Reproducible Demo
git clone https://github.com/stereobooster/async-precious.git
cd async-precious
git checkout styleguidist-bug
As far as I understand this happens due to #3776. Related issue https://github.com/styleguidist/react-styleguidist/issues/987
Issue Analytics
- State:
- Created 5 years ago
- Reactions:4
- Comments:18 (11 by maintainers)
Top Results From Across the Web
babel/plugin-syntax-dynamic-import
Working with Webpack and @babel/preset-env. Currently, @babel/preset-env is unaware that using import() with Webpack relies on Promise internally.
Read more >Webpacker error related to module babel-plugin-syntax ...
<path_to_my_app>/node_modules/@babel/plugin-syntax-dynamic-import/ is installed. Similar issues reported in SO, but I think I've tried them all.
Read more >Module Methods - webpack
Version 2 of webpack supports ES6 module syntax natively, meaning you can use import and export without a tool like babel to handle...
Read more >How to transpile ES modules with webpack and Node.js
Learn how webpack interacts with and supports ES modules in this deep ... can instruct the Node.js runtime to treat JavaScript code as...
Read more >ES2020: `import()` – dynamically importing ES modules - 2ality
It enables dynamic loading of ECMAScript modules and is explained in ... Then import() helps, because you can put such functionality into ......
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 FreeTop 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
Top GitHub Comments
I’m not sure of the best resolution here – we received significant flak about not compiling
node_modules
, so if this ends up breaking packages who use experimental syntax only understood by a bundler [webpack], I think I can live with that.This case might be semi-unique because it uses the
import()
specification, which we suggest for usage – I wouldn’t see major harm in allowing this to be parsed so that webpack can handle it.Where I’m torn is that if the
import()
specification changes, we are willing to provide codemods to upgrade acreate-react-app
codebase, though updating packages may be more difficult. However, since this is already widely adopted in the community (by webpack users), I think the potential for change here is minimal.I’d like to hear what other maintainers think on the subject, @iansu @gaearon.
from react-loadable homepage