dynamic import are unrecognized in 3.0.0-next.b0cbf2ca, compile fails #6673
Description
Is this a bug report?
Yes
Did you try recovering your dependencies?
npm version 6.8.0
Which terms did you search for in User Guide?
Environment
I used the command, but I got an error instead.
(node:16088) UnhandledPromiseRejectionWarning: Error: The system cannot find the path specified.
at Function.e.exports.sync (C:\Users\jonas\AppData\Roaming\npm\node_modules\create-react-app\node_modules\envinfo\dist\envinfo.js:1:7778)
at Object.copySync (C:\Users\jonas\AppData\Roaming\npm\node_modules\create-react-app\node_modules\envinfo\dist\envinfo.js:1:104976)
at Object.t.writeSync.e [as writeSync] (C:\Users\jonas\AppData\Roaming\npm\node_modules\create-react-app\node_modules\envinfo\dist\envinfo.js:1:123499)
at C:\Users\jonas\AppData\Roaming\npm\node_modules\create-react-app\node_modules\envinfo\dist\envinfo.js:1:124274 at Promise.all.then.e (C:\Users\jonas\AppData\Roaming\npm\node_modules\create-react-app\node_modules\envinfo\dist\envinfo.js:1:124289)
(node:16088) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwinginside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:16088) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
I'm on Windows 10
- node v11.8.0
- npm v6.8.0
- react-scripts v3.0.0-next.b0cbf2ca
- react & react-dom v16.8.1
Steps to Reproduce
(Write your steps here:)
- Create a new project with the latest prerelease (3.0.0-next.b0cbf2ca)
- Import a module dynamically (eg. const AsyncApp = lazy(() => import('./App')))
- npm start -> Failed to compile
Expected Behavior
(Write what you thought would happen.)
The build would pass, as it does in previous versions.
Actual Behavior
Reproducible Demo
(Paste the link to an example project and exact instructions to reproduce the issue.)

Activity
ianschmitz commentedon Mar 18, 2019
If you have a chance do you mind trying Node 10.x? We've had some reports of issues on the latest Node 11.x.
I just tested using Node 10.15.1 with the following in my
index.jsand it worked fine:ianschmitz commentedon Mar 18, 2019
With regards to
envinfothrowing, can you make surecreate-react-appisn't installed globally? You can follow the instructions in our docsnimrossum commentedon Mar 18, 2019
@ianschmitz
Ah, thank you. I was wondering why it wasn't working.
wasker commentedon Mar 19, 2019
This bug looks like this bug on webpack, which was root-caused to this bug on npm.
iansu commentedon Mar 19, 2019
It's unclear if webpack is going to do anything to fix this issue or if it's just going to be fixed in npm. We'll keep an eye on the webpack issue and see if they release a new version before we publish 3.0 final.
iansu commentedon Apr 21, 2019
Is anyone able to reproduce this issue with the latest alpha release?
cedmax commentedon Apr 23, 2019
@iansu I have the same problem with the v3.0.0 (npm v6.9, node v10.15.1)
nimrossum commentedon Apr 23, 2019
@ianschmitz
@iansu
I've tried downgrading to node 10.15.3, removing
node_modulesandpackage-lock.jsonand tested the recently released 3.0.0 version.Can still reproduce.
Envinfo:
Btw, I still get an error with
npx create-react-app --info:I get this error everytime I try to use
npxwith eitherreact-scriptsorcreate-react-app. I don't get this error with react-scripts@2I suspect it has something to do with my user folder containing a space:
C:\Users\Jonas Røssumand somehow gets interpreted wrongly.iansu commentedon Apr 23, 2019
There is an npm/npx bug with usernames that contain a space. I'm not sure if that's related to the dynamic import issue. Maybe try copying your code to a different directory, outside of your user's account, that doesn't have any spaces in the name. Even if that's not a good long term solution it might help us troubleshoot this.
npx also uses npm's cache which is probably why you're seeing an error with
--info. I would try clearing the cache or at least removingcreate-react-appfrom the cache and then run that command again.11 remaining items
Silic0nS0ldier commentedon May 9, 2019
@kuzman Is this with a clean project as well (as in newly created using the CLI tool)? If not, could you put a list of your dependencies up? I'd like to see if I can get that scenario accounted for in my reproduction repo (https://github.com/Silic0nS0ldier/CRA-6673).
nimrossum commentedon May 15, 2019
I finally found a solution that works for me, suggested by @andybarsby and @kylehalleman
#6873 (comment)
Running
npm i --save-dev acorn-dynamic-import@3fixes the issue for me. No other solution have worked, I've tried all of these:npm installDoes updating the
acorn-dynamic-importdependency solve the issue for anyone else? (for people, where the steps mentioned didn't solve the issue)delaaxe commentedon May 15, 2019
Switched to yarn and worked as expected
bradfmd commentedon May 15, 2019
@joglr I have this problem and none of the previous suggestions worked for me. I tried your recommendation and can confirm it solves the issue for me
Silic0nS0ldier commentedon May 15, 2019
Proposed workaround works for my reproduction repo as well.
Looking in
package-lock.jsonI can only see 1 other version ofacorn-dynamic-import(v4) which is required by webpack. Tracking down something that usesacorn-dynamic-importbut doesn't itself depend on it sounds like the next step towards getting this properly fixed.Silic0nS0ldier commentedon May 16, 2019
Doesn't look like anything else is depending on
acorn-dynamic-importaside fromwebpack. By default, both packages are living at the top level innode_modules(no duplicate copies). Odd that adding the older version ofacorn-dynamic-importfixes this issue at all since webpack shouldn't even be touching the top level one when its ownnode_modulesfolder has what it wants. That is, unless something has added a require hook and changed dependency resolution logic in the process.Perhaps related, perhaps not. I've been digging into webpack to try and track down where it all falls apart and I've noticed some errors in generated code. The first in
html-webpack-plugindue to a strict mode violation (withkeyword is used), and our failing source (unexpected token and'import' and 'export' may appear only with 'sourceType: module'). That last error could be a lead.nitinkaveriappa commentedon May 23, 2019
Was facing the same issue. Adding
npm i --save-dev acorn-dynamic-import@3fixed the issue.ViktorAksionov commentedon May 24, 2019
I had the same issue and fixed it installing
acorn@6.jest is using acorn@5 and looks like somehow it creates a problem. Also you can
dedupeacorn.AndrePinto-NET commentedon Jul 5, 2019
Thank you @joglr
Dante-dan commentedon Jul 11, 2019
Thank you @nitinkaveriappa
oznekenzo commentedon Jul 16, 2019
Thank you @joglr!
gonzofish commentedon Jul 30, 2019
Has anyone tried installing
acorn-dynamic-import@4? I think it's working for me...but after trying so much, I'm always wary to say "it works!"fix build
quintmouthaan commentedon Nov 11, 2019
@joglr thank you very much, it worked for me
@gonzofish interestingly enough, installing acorn-dynamic-import@4 did not work for me, I had to install v3
Fix for Issue with Lazy Import