question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Enable Babel syntax support for the dynamic import specification within `node_modules` such that webpack can handle the statements

See original GitHub issue

Is 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

  1. git clone https://github.com/stereobooster/async-precious.git
  2. cd async-precious
  3. git checkout styleguidist-bug
  4. yarn
  5. 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

  1. git clone https://github.com/stereobooster/async-precious.git
  2. cd async-precious
  3. 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:closed
  • Created 5 years ago
  • Reactions:4
  • Comments:18 (11 by maintainers)

github_iconTop GitHub Comments

3reactions
Timercommented, May 18, 2018

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 a create-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.

3reactions
stereoboostercommented, May 17, 2018

from react-loadable homepage

const LoadableComponent = Loadable({
  loader: () => import('./my-component'), // <-- dynamic import
  loading: Loading,
});
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found