next.js: 8.0.0 - dynamic import causing 'You may need an appropriate loader...' error
Bug report
Just upgraded to 8.0.0 and I’m really excited! I’ve run into an issue though that is preventing my project from compiling
Describe the bug
So when I run dev I am getting the following issue
You may need an appropriate loader to handle this file type.
|
|
> import('./noop');
| var _window = window,
| assetPrefix = _window.__NEXT_DATA__.assetPrefix;
It seems to be coming from webpack 4.29.0 (see here).
It looks like the issue was fixed with this which declared acorn": "^6.0.5 as a dependency but the change doesn’t seem to be present on master
Maybe I upgraded too soon?
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 92
- Comments: 59 (18 by maintainers)
Commits related to this issue
- Add webpack 4.28.4 as a dev dependency, see https://github.com/zeit/next.js/issues/6240https://github.com/zeit/next.js/issues/6240 — committed to uzh-bf/klicker-uzh by rschlaefli 8 years ago
- Update package.json Test if webpack 4.29.6 will fix issues with https://github.com/zeit/next.js/issues/6240 — committed to tbartlett-vcc/next.js by tbartlett-vcc 8 years ago
- fix: add acorn as dependency to fix an error with next/webpack dynamic import More info: https://github.com/zeit/next.js/issues/6240 https://github.com/webpack/webpack/issues/8656 — committed to opencollective/opencollective-frontend by znarf 8 years ago
- fix: add acorn as dependency to fix an error with next/webpack dynamic import More info: https://github.com/zeit/next.js/issues/6240 https://github.com/webpack/webpack/issues/8656 — committed to opencollective/opencollective-frontend by znarf 8 years ago
- fix: add acorn as dependency to fix an error with next/webpack dynamic import More info: https://github.com/zeit/next.js/issues/6240 https://github.com/webpack/webpack/issues/8656 — committed to opencollective/opencollective-frontend by znarf 8 years ago
- Tracking branch for Next.js’s upcoming TypeScript The current 8.1.1 canary track includes native TypeScript support, which includes official types for Next.js objects and out-of-the-box TypeScript co... — committed to CityOfBoston/digital by deleted user 8 years ago
- fix(ci): see https://github.com/zeit/next.js/issues/6240 — committed to coderplanets/coderplanets_web by mydearxym 7 years ago
- Upgrade to webpack with latest acorns Closes https://github.com/zeit/next.js/issues/6240 — committed to vercel/next.js by Timer 7 years ago
- Upgrade to webpack with latest acorns (#7795) Closes https://github.com/zeit/next.js/issues/6240 — committed to vercel/next.js by Timer 7 years ago
Ok here is the winning combo (made sure is 100% reproducible): My project already had next v7
npm install next@latest-> installs next v8.0.1 but warns about acornnpm run dev-> runs next and fails with the error described in this git issuenpm install acornnpm run dev-> runs next and fails with the error described in this git issuenpm install next@latest-> no warningsnpm run devit works!!! 🎉Conclusion The key is to install acorn before next
We are also seeing this issue and followed the threads for a workaround.
next build) builds and runs fine.Following the the issues linked in the thread and installing
webpack@4.28.4and@babel/core@7.2.2as devDependancies did resolve this.(This also resolved the error about the Acorn package, which we do not have as a direct dependancy.)
I had the same issue, also after updating
webpackand@babel/core. Removing mypackage-lock.jsonandnode_modulesand doing a fresh install solved the issue.Deleting
node_modulesandpackage-lock.jsondidn’t resolve this for me, but installingwebpack@4.28.4as a dev dependency did, as @iaincollins suggested.Using Yarn to install dependencies did the trick for me. Super weird.
@Timer I’m running next@9.0.4 and still having the issue. I’ve tried:
yarn add acornand then runningyarn next@latestto no avail@timneutkens I finally discovered last night that my issue was caused by #6273. As I mentioned in that thread, the error goes away if I modify my
next/babelpreset to['next/babel', { 'transform-runtime': { useESModules: false } }].EDIT: I just published a test repo, see discussion in #6273.
I have the same behaviour in TypeScript files:
I have a different error related to imports which might have the same root cause:
Everything is fine if I downgrade to next@7.0.3
This fixed the issue for me too, thanks ! 👏
Will be fixed by https://github.com/zeit/next.js/issues/6940
Same as @Soundvessel
Installing
acornpriornext@8fixed the issue.This happens for me directly between
v8.0.0-canary.11andv8.0.0-canary.12https://github.com/zeit/next.js/compare/v8.0.0-canary.11...v8.0.0-canary.12Installing
webpack@4.28.4and@babel/core@7.2.2as devDependencies as @iaincollins suggested fixes this for me as well.So was it some kind of dependency resolution? @vasco3 that solved my problem.
Removing
node_modulesandpackage-lock.jsonthen reinstalling resolved this for me as well.Thanks, this solution solved the issue for me. I had been working on another Node.js project (not Next.js) where I’d upgraded my version of Node to the latest - this seems to be the cause of the issue. Where the solution to remove the lock.json and node_modules, then re-install the packages worked perfectly. Thanks.
The final resolution steps should be to
rm package-lock.jsonandrm -rf node_modules, then reinstall.It’s important to note that this is only fixed in Next 9.
This doesn’t seem to fix the issue for me. Dealing with an older code base that can’t quite upgrade to the new features yet, and i still need a transpiled server.
I’ve done the above steps, and they don’t solve the issue. I’m not even using dynamic imports 😕
Thanks a ton, this fixed the problem. 👏👏
thanks! proves once again that order matters! saved me.
I used Yarn to install dependencies too and it works)
To clarify I did not need Acorn to resolve the issue. Try to uninstall Next using the command line instead of just deleting
node_modules.I believe that using the command line to uninstall Next removes the cause of trouble from an NPM cache outside of
node_modules.I also updated Node and NPM beforehand but that didn’t help until I properly reinstalled.
Got 8.0.3 running without Acorn.
It appears NPM was caching next incorrectly. Even when deleting my
node_modulesfolder andpackage-lockrerunningnpm ithe issue would persist. Actually using the NPM CLI to uninstall next appears to have removed it from the cache properly and after a reinstall without Acorn it is up and running.I ran in to the same issue. Removing both
node_modulesandpackage-lock.jsonand reinstalling did fix it for me. It’s important to remove both the directory and lock file before reinstalling, just in case that’s the issue some are hitting.Facing the same issue as @AndrewIngram on a complex project. The issue only appears for
next@8.0.0in dev mode, not when compiling for production.For me this was fixed by upgrading @babel/core:
For some reason we have that as direct dependency currently.
I’m facing the same error. Installing
acorndoesn’t work for me either. FYI, I usets-nodefor running my express server.