-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
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
Enable Babel syntax support for the dynamic import specification within node_modules
such that webpack can handle the statements
#4477
Comments
I'm not the maintainer, but can reproduce the bug above. You can also simply make a reference to the component and just start create-react-app.
import EditorLoader from '../node_modules/react-styleguidist/lib/rsg-components/Editor/EditorLoader'
|
I can confirm I experience the same issue, but I'm not sure on which side (CRA vs Styleguidist) it falls. styleguidist is a dependency, and as such is going through the dependencies.js preset instead of the index.js one. Everything that's not in the app path ( From what I understand of the issue, either:
Note: I can confirm that the dynamic import syntax issue is the only thing preventing styleguidist from running properly. For example, manually adding |
But create-react-app itself supports dynamic import, that is how react-loadable works in c-r-a. |
I guess the whole point of why |
from react-loadable homepage const LoadableComponent = Loadable({
loader: () => import('./my-component'), // <-- dynamic import
loading: Loading,
}); |
Yes, it's in their homepage, as an example of a code that you would put in your own app, so that's fine. I meant that they are not using the dynamic import syntax in their own codebase, and that's probably why it stills works with CRA@next |
c-r-a itself supports dynamic import, I can use dynamic import in my app code (based on c-r-a). Why other projects can not use it? This doesn't make sense to me |
I too can use dynamic imports in my CRA app code. Starting from the next version of CRA, non-basic ES in node_modules isn't allowed (see my comment with the links to the codebase that does that). You can still use most of the advanced ES6 syntax/features in your app code. |
We only compile stage 4 features that are used in your dependencies; there is no guarantee a stage 3 will advance to stage 4 without changes. This is by design. Compiling away experimental specifications is a slippery slope to causing churn in the community by supporting features which may never make it into the language and then break backwards compatibility, preventing future advancement. |
@Timer this totally makes sense, but what is the resolution here? Should we reopen ticket in styleguidist? Or can I opt-out node modules compilation for this package? |
I'm not sure of the best resolution here -- we received significant flak about not compiling This case might be semi-unique because it uses the Where I'm torn is that if the I'd like to hear what other maintainers think on the subject, @iansu @gaearon. |
node_modules
such that webpack can handle the statements
@stereobooster I'd reopen the issue on their end for now; it'd be nice if they could drop usage of They seem to do some really fishy stuff which may break at any time, it's discouraging to see things like this (I'm not sure if this stuff is imported by usage with |
Let's not call some code “fishy” only because you don’t know what it does and constraints we have. It also has nothing to do with the What would you suggest to use instead of the |
Thanks @ridem for detailing the issue. I've been trying to figure out why my package using dynamic imports wasn't working when it was used with the CRA v2 branch. We currently use Then I saw this issue and reading through it, learned that CRA's support for dynamic imports is only for "app" code and does not support code imported from node_modules. As @Timer mentioned, "We only compile stage 4 features that are used in your dependencies;" and I think that makes sense. I would encourage the CRA team to reconsider this stance in regards to adding the babel plugin-syntax-dynamic-import to dependencies.js or note on the README section for dynamic imports that they are only supported in "app" code. |
Looks like this is resolved via this commit: e8b0ee8#diff-e4eb38a3161bed144100754a3e97763d |
seems to be solved, but haven't tested it. Is there alpha release with this commit? |
Yes @stereobooster, see |
Is this a bug report?
Yes
Did you try recovering your dependencies?
(Write your answer here.)
Which terms did you search for in User Guide?
experimental syntax 'dynamicImport'
Environment
But this is what is relevant:
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
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 styleguidist/react-styleguidist#987
The text was updated successfully, but these errors were encountered: