Skip to content
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

8.0.0 - dynamic import causing 'You may need an appropriate loader...' error #6240

Closed
dunika opened this issue Feb 11, 2019 · 59 comments · Fixed by #7301 or #7795
Closed

8.0.0 - dynamic import causing 'You may need an appropriate loader...' error #6240

dunika opened this issue Feb 11, 2019 · 59 comments · Fixed by #7301 or #7795
Assignees
Labels
Upstream Related to using Next.js with a third-party dependency. (e.g., React, UI/icon libraries, etc.).
Milestone

Comments

@dunika
Copy link

dunika commented Feb 11, 2019

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?

@dimensi
Copy link

dimensi commented Feb 11, 2019

I got same problem. Can't start develop mode. I updated npm to the latest version and also tried to install the acorn package, but did not help.
@timneutkens

@AndrewIngram
Copy link

I have a different error related to imports which might have the same root cause:

/Users/andrewingram/Repositories/tego/website-next/node_modules/@babel/runtime-corejs2/helpers/esm/typeof.js:1
(function (exports, require, module, __filename, __dirname) { import _Symbol$iterator from "../../core-js/symbol/iterator";
                                                                      ^^^^^^^^^^^^^^^^

SyntaxError: Unexpected identifier

Everything is fine if I downgrade to next@7.0.3

@timneutkens timneutkens added the Upstream Related to using Next.js with a third-party dependency. (e.g., React, UI/icon libraries, etc.). label Feb 11, 2019
@timneutkens
Copy link
Member

timneutkens commented Feb 11, 2019

@AndrewIngram can you provide a reproduction? curious to look into that one. It sounds related to @babel/runtime, not webpack.

@incleaf
Copy link

incleaf commented Feb 11, 2019

I'm facing the same error. Installing acorn doesn't work for me either. FYI, I use ts-node for running my express server.

@TomiTakussaari
Copy link

TomiTakussaari commented Feb 11, 2019

For me this was fixed by upgrading @babel/core:

-        "@babel/core": "^7.1.0",
+        "@babel/core": "7.2.2",

For some reason we have that as direct dependency currently.

@cnasc
Copy link

cnasc commented Feb 11, 2019

Experiencing same issue and error message. @babel/core is set to "7.2.2" so that may not be the issue.

@iaincollins
Copy link
Contributor

We are also seeing this issue and followed the threads for a workaround.

  • Production (with next build) builds and runs fine.
  • Running in development mode produces the same error as OP.
  • We invoke Next.js programmatically (we use it with Express currently).
  • Updating @babel/core to 7.2.2 did not resolve this for us.

Following the the issues linked in the thread and installing webpack@4.28.4 and @babel/core@7.2.2 as devDependancies did resolve this.

(This also resolved the error about the Acorn package, which we do not have as a direct dependancy.)

@kpoelhekke
Copy link

I had the same issue, also after updating webpack and @babel/core. Removing my package-lock.json and node_modules and doing a fresh install solved the issue.

@jescalan
Copy link
Contributor

jescalan commented Feb 11, 2019

Same issue here, unfortunately. Here's a replication: https://github.com/jescalan/nextjs-test/tree/je.canary

Static build and export works wonderfully, it's just dev mode that errors. Neither babel nor webpack are installed as dependencies.

@jescalan
Copy link
Contributor

Just fixed with with a removal of package-lock.json and regenerate. The last commit on that branch shows which updates were made to package-lock.json -- hopefully this helps to pin down the cause!

@pdlug
Copy link

pdlug commented Feb 11, 2019

Removing node_modules and package-lock.json then reinstalling resolved this for me as well.

@bitmap
Copy link

bitmap commented Feb 11, 2019

Deleting node_modules and package-lock.json didn't resolve this for me, but installing webpack@4.28.4 as a dev dependency did, as @iaincollins suggested.

@paulschneider
Copy link

Also experiencing this problem but outside of this package; Downgrading to a lower version of node (v9.11 [a colleagues working version], installing webpack@4.28.4 and reinstalling node_modules fixed this for me.

@icflorescu
Copy link

I have a different error related to imports which might have the same root cause:

/Users/andrewingram/Repositories/tego/website-next/node_modules/@babel/runtime-corejs2/helpers/esm/typeof.js:1
(function (exports, require, module, __filename, __dirname) { import _Symbol$iterator from "../../core-js/symbol/iterator";
                                                                      ^^^^^^^^^^^^^^^^

SyntaxError: Unexpected identifier

Everything is fine if I downgrade to next@7.0.3

Facing the same issue as @AndrewIngram on a complex project. The issue only appears for next@8.0.0 in dev mode, not when compiling for production.

@shaunchurch
Copy link

shaunchurch commented Feb 12, 2019

I ran in to the same issue. Removing both node_modules and package-lock.json and 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.

@schabluk
Copy link

schabluk commented Feb 12, 2019

I have the same behaviour in TypeScript files:

error  in ./stores/index.ts

Module parse failed: Export 'IStore' is not defined (77:9)
You may need an appropriate loader to handle this file type.
|   return Store;
| };
> export { IStore, IStoreSnapshotIn, IStoreSnapshotOut };

 @ ./pages/_app.tsx 16:0-37 38:24-32 83:18-26

@timneutkens
Copy link
Member

@icflorescu it's impossible to solve the issue without a clear reproduction. Please provide one so that we can investigate further 🙏

@timneutkens
Copy link
Member

@icflorescu could you create a new issue for it (including reproduction) because it's not the same as this one 🙏

@icflorescu
Copy link

icflorescu commented Feb 13, 2019

@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/babel preset to ['next/babel', { 'transform-runtime': { useESModules: false } }].

EDIT: I just published a test repo, see discussion in #6273.

@BiscuiTech
Copy link

In my case, a simple complete re-install of the node_modules directory fixed this issue. It might related to the internal dependencies of the modules and the left over modules.

@goshdarnheck
Copy link

I have the same issue (I also get the same error when using dynamic imports, I wrote about it on Spectrum https://spectrum.chat/users/matthew-rapati?thread=c677c233-8b02-447f-aff0-97b3399a493f).

I tried removing node_modules, package-lock.json and clearing my npm cache, but it did not resolve the issue. If I have a chance I will try to create a small reproduction of the issue.

@obedparla
Copy link
Contributor

Installing acorn fixed this issue for me. It is merged already on canary but not yet on master. #6137

@timneutkens
Copy link
Member

Installing acorn in Next.js doesn't solve the issue.

@ograycode
Copy link

ograycode commented Feb 14, 2019

Where I work, this has impacted us when trying to upgrade to next 8.

@Robbatron
Copy link

Using Yarn to install dependencies did the trick for me. Super weird.

@vasco3
Copy link
Contributor

vasco3 commented Feb 15, 2019

Ok here is the winning combo (made sure is 100% reproducible):
My project already had next v7

  1. npm install next@latest -> installs next v8.0.1 but warns about acorn
  2. npm run dev -> runs next and fails with the error described in this git issue
  3. npm install acorn
  4. npm run dev -> runs next and fails with the error described in this git issue
  5. npm install next@latest -> no warnings
  6. npm run dev it works!!! 🎉

Conclusion
The key is to install acorn before next

@alexbaumgertner
Copy link

@vasco3 Big thanks! It works for me:

npm install acorn
npm run dev // -> runs next and fails with the error described in this git issue
npm install next@latest // -> no warnings
npm run dev // it works!!! 🎉

@vscode1111
Copy link

I used Yarn to install dependencies too and it works)

@ghost
Copy link

ghost commented May 29, 2019

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 acorn
  • npm run dev -> runs next and fails with the error described in this git issue
  • npm install acorn
  • npm run dev -> runs next and fails with the error described in this git issue
  • npm install next@latest -> no warnings
  • npm run dev it works!!! 🎉

Conclusion:
The key is to install acorn before next

thanks! proves once again that order matters! saved me.

fionawhim pushed a commit to CityOfBoston/digital that referenced this issue May 30, 2019
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 compilation. This is good! But it means we have to adapt some
of our existing TypeScript stuff.

As of this writing, Next.js enforces that the app directory contain its
own tsconfig.json file (vercel/next.js#7333), so this PR adds those as
necessary, inheriting from the parent package’s configuration. It also
requires a handful of specific configurations, so those are included as
well (vercel/next.js#7361) in those files.

This change also hoists acorn and acorn-dynamic-import because those two
packages need to be in a consistent place relative to each other and
webpack. (vercel/next.js#6240)

Currently the 'next' module does not export a type for its constructor
function, so we switch 'import next' to 'const next = require' to avoid
the typechecking.

We add "export {}" to the bottom of files that don’t do their own import
/ exporting to avoid an error due to the required "isolatedModules"
setting. (These can be removed if "isolatedModules" is removed.)

The bulk of the changes are updating _app and _document classes to the
nice new types.
@naomiHauret
Copy link

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 acorn
  • npm run dev -> runs next and fails with the error described in this git issue
  • npm install acorn
  • npm run dev -> runs next and fails with the error described in this git issue
  • npm install next@latest -> no warnings
  • npm run dev it works!!! tada

Conclusion:
The key is to install acorn before next

This fixed the issue for me too, thanks ! 👏

mydearxym added a commit to coderplanets/coderplanets_web that referenced this issue Jun 15, 2019
@dixitpeeyush
Copy link

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 acorn

* `npm run dev` -> runs next and fails with the error described in this git issue

* `npm install acorn`

* `npm run dev` -> runs next and fails with the error described in this git issue

* `npm install next@latest` -> no warnings

* `npm run dev` it works!!! 🎉

Conclusion:
The key is to install acorn before next

Thanks a ton, this fixed the problem. 👏👏

@TidyIQ
Copy link

TidyIQ commented Jul 5, 2019

Will this be fixed in the canary branch any time soon?

@Timer
Copy link
Member

Timer commented Jul 5, 2019

@TidyIQ we will be trying to fix it soon! It's important to note that this is a npm bug.

@dav-is dav-is removed their assignment Jul 8, 2019
@c0b41
Copy link
Contributor

c0b41 commented Jul 8, 2019

@Timer webpack already fixed this problem see webpack/webpack#9370

@Timer Timer added this to the 9.0.1 milestone Jul 8, 2019
Timer added a commit that referenced this issue Jul 8, 2019
Timer added a commit that referenced this issue Jul 8, 2019
@cryptiklemur
Copy link
Contributor

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 :/

Compiling client app. 
Compiling server app. 
[ error ] ./node_modules/next/dist/client/next-dev.js 23:6
Module parse failed: Unexpected token (23:6)
You may need an appropriate loader to handle this file type.
| 
| 
> import('./dev/noop'); // Support EventSource on Internet Explorer 11
| 
| if (!window.EventSource) {
[ wait ]  compiling ...
[ error ] ./node_modules/next/dist/client/next-dev.js 23:6
Module parse failed: Unexpected token (23:6)
You may need an appropriate loader to handle this file type.
| 
| 
> import('./dev/noop'); // Support EventSource on Internet Explorer 11
| 
| if (!window.EventSource) {
2019-07-13T08:07:59.942Z app:server:log Connected to redis
2019-07-13T08:07:59.947Z app:server:log > Ready on http://localhost:3000

@zargold
Copy link

zargold commented Jul 15, 2019

I may have solved this above problem by rm-ing node-modules and re-installing, but maybe not re-installing everything there might be a specific package which is causing this

@Timer
Copy link
Member

Timer commented Jul 15, 2019

The final resolution steps should be to rm package-lock.json and rm -rf node_modules, then reinstall.

It's important to note that this is only fixed in Next 9.

@neocybereth
Copy link

@Timer I'm running next@9.0.4 and still having the issue. I've tried:

  1. removing next, adding acorn with yarn add acorn and then running yarn next@latest to no avail
  2. removing all node_modules and yarn.lock and reinstalling. Anybody else still seeing this issue? I've only begun to experience it with react-datepicker

@timneutkens
Copy link
Member

@Sm00g15 it's quite hard to help you when a reproduction is not provided. Maybe you installed webpack manually?

@nicktaras
Copy link

I had the same issue, also after updating webpack and @babel/core. Removing my package-lock.json and node_modules and doing a fresh install solved the issue.

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.

@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Upstream Related to using Next.js with a third-party dependency. (e.g., React, UI/icon libraries, etc.).
Projects
None yet
Development

Successfully merging a pull request may close this issue.