Create-react-app: v2: Dynamic import returns object instead of function

Created on 26 Sep 2018  路  5Comments  路  Source: facebook/create-react-app

Is this a bug report?

Yes

Did you try recovering your dependencies?

Yes

Which terms did you search for in User Guide?

Dynamic import

Environment

CRA v2.0.0

Steps to Reproduce / Reproducible Demo

After updating react-scripts to v2 I can see an error Unhandled Rejection (TypeError): throttle is not a function.
In my code I do a dynamic import of lodash throttle. I created a codesandbox to reproduce what I do: https://codesandbox.io/s/4jp4j3l360 if you test with the deployed version you will notice in the console that an object is returned: https://csb-4jp4j3l360-jfpilaxokx.now.sh/

Expected Behavior vs Actual Behavior

The dynamic import should return a function isntead of an object.

documentation

Most helpful comment

Yes, see https://medium.com/webpack/webpack-4-import-and-commonjs-d619d626b655. We should document this as breaking behavior and provide migration instructions.

All 5 comments

Wait, I think this is expected. You have to import('').default, I believe.

Yes, see https://medium.com/webpack/webpack-4-import-and-commonjs-d619d626b655. We should document this as breaking behavior and provide migration instructions.

Thank you for your answer, your solution works.

We will add this to the breaking migration instructions.

Documented in the migration instructions.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

xiaoxiangmoe picture xiaoxiangmoe  路  89Comments

ericvicenti picture ericvicenti  路  83Comments

akctba picture akctba  路  80Comments

ericdfields picture ericdfields  路  78Comments

gaearon picture gaearon  路  86Comments