Next.js: Module parse failed: Unexpected token (2:4) You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders

Created on 27 Oct 2019  ·  18Comments  ·  Source: vercel/next.js

Bug report

I have been following the exact steps for starting a Next.js app here: https://nextjs.org/learn/basics/getting-started/setup

I also followed the steps for starting a next.js app on Shopify (I want to develop an app there).

I have worked heavily with react but never with next. When I go running the npm run dev command I keep getting the following error:

```[ error ] D:/webDev/shopifyApps/hello-next/pages/index.js 2:4
Module parse failed: Unexpected token (2:4)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| const Index = () => (

<div>

|

Hello Next.js


|

[ event ] build page: /next/dist/pages/_error
[ wait ] compiling ...
[ error ] D:/webDev/shopifyApps/hello-next/pages/index.js 2:4
Module parse failed: Unexpected token (2:4)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| const Index = () => (

|

Hello Next.js


|

ModuleParseError: Module parse failed: Unexpected token (2:4)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| const Index = () => (

|

Hello Next.js


|

at handleParseError (D:\webDev\shopifyApps\hello-next\node_modules\webpack\lib\NormalModule.js:461:19)
at doBuild.err (D:\webDev\shopifyApps\hello-next\node_modules\webpack\lib\NormalModule.js:495:5)
at runLoaders (D:\webDev\shopifyApps\hello-next\node_modules\webpack\lib\NormalModule.js:354:12)
at D:\webDev\shopifyApps\hello-next\node_modules\loader-runner\lib\LoaderRunner.js:373:3
at iterateNormalLoaders (D:\webDev\shopifyApps\hello-next\node_modules\loader-runner\lib\LoaderRunner.js:214:10)
at D:\webDev\shopifyApps\hello-next\node_modules\loader-runner\lib\LoaderRunner.js:205:4
at process.nextTick (D:\webDev\shopifyApps\hello-next\node_modules\enhanced-resolve\lib\CachedInputFileSystem.js:85:15)
at processTicksAndRejections (internal/process/next_tick.js:74:9)
[ event ] client pings, but there's no entry for page: /_error
[ event ] disposing inactive page(s): /, /next/dist/pages/_error

Most helpful comment

This happened to me because I was importing shared JSX code from outside of my nextjs app's directory from elsewhere in my mono repo. This was my solution: https://github.com/zeit/next.js/issues/706#issuecomment-569041997

All 18 comments

Please follow the issue template, and if possible provide a repo that reproduces the problem. This speeds up things a lot 🙏

I guess one of the things I forgot to mention in the "issue template" was that you should follow the same exact instructions I followed on the Next.js steps for getting started.

I will attach a link to a repo.

https://github.com/kylerRenneker/hello-next

The above repo is the exact code that is resulting in the mentioned error.

I do not have any problem running any other (non-nextjs) node apps locally.

I'm assuming you have a .babelrc somewhere up the directory tree that causes the code to be compiled incorrectly.

I just looked at the documentation and the typical Next.js project will not have a .babelrc file by default but one can be added.

Something to note is I even tried the create-next-app method as well as the manual method and I am still getting the same error when navigating to my local server.

I should mention that before I go to http://localhost:3000 in my browser the develop server appears to start fine:

[ wait ] starting the development server ... [ info ] waiting on http://localhost:3000 ... [ ready ] compiled successfully - ready on http://localhost:3000 [ wait ] compiling ... [ ready ] compiled successfully - ready on http://localhost:3000

But as soon as I navigate to the server url in the browser I am met with the same error on each attempt:

```[ event ] build page: /
[ wait ] compiling ...
[ error ] D:/webDev/shopifyApps/hello-next/pages/index.js 2:4
Module parse failed: Unexpected token (2:4)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| const Index = () => (

<div>

|

Hello Next.js


|

[ event ] build page: /next/dist/pages/_error
[ wait ] compiling ...
[ error ] D:/webDev/shopifyApps/hello-next/pages/index.js 2:4
Module parse failed: Unexpected token (2:4)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| const Index = () => (

|

Hello Next.js


|

ModuleParseError: Module parse failed: Unexpected token (2:4)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| const Index = () => (

|

Hello Next.js


|

at handleParseError (D:\webDev\shopifyApps\hello-next\node_modules\webpack\lib\NormalModule.js:461:19)
at doBuild.err (D:\webDev\shopifyApps\hello-next\node_modules\webpack\lib\NormalModule.js:495:5)
at runLoaders (D:\webDev\shopifyApps\hello-next\node_modules\webpack\lib\NormalModule.js:354:12)
at D:\webDev\shopifyApps\hello-next\node_modules\loader-runner\lib\LoaderRunner.js:373:3
at iterateNormalLoaders (D:\webDev\shopifyApps\hello-next\node_modules\loader-runner\lib\LoaderRunner.js:214:10)
at D:\webDev\shopifyApps\hello-next\node_modules\loader-runner\lib\LoaderRunner.js:205:4
at process.nextTick (D:\webDev\shopifyApps\hello-next\node_modules\enhanced-resolve\lib\CachedInputFileSystem.js:85:15)
at processTicksAndRejections (internal/process/next_tick.js:74:9)
[ event ] client pings, but there's no entry for page: /_error

@kylerRenneker you don't need a .babelrc in your project, right. But he means that perhaps you have a .babelrc file up in your directory tree, maybe at D:\webDev\shopifyApps or D:\webDev\ and so on, that is being utilized and is compiling the project incorrectly.
I am running your example and it is working fine.

@kylerRenneker can you provide the full output from booting up Next.js to the error? I'm quite certain you have a .babelrc up the directory tree this means it's not in the directory that you're booting up Next.js in but actually in one of the directories above that. The cli output will show you something along the lines of "Using custom .babelrc <location>" 👍

@rafaelalmeidatk @timneutkens
You all must be right...I ran create-next-app just directly on my desktop, cd into the folder, and ran npm run dev and it worked.

I guess Ill will have to dig around for that .bablrc file unless yall know of another solution??

Is there a way to prevent next.js app from looking for that file?

Well, I wish I had more to add than this...but it spontaneously started working.

I deleted the old project folder and started from scratch following the same steps as before and now the project is running.

This happened to me because I was importing shared JSX code from outside of my nextjs app's directory from elsewhere in my mono repo. This was my solution: https://github.com/zeit/next.js/issues/706#issuecomment-569041997

Excuse me.
I'm following the same guide, and came into the same problem.
I don't understand how I can overcame this problem, what is the answer to this problem?
I repeated everything but the problem repeated.

I'm getting this error, too. I'm trying to set up npx create-next-app but i always see this error. How can i fix this?

@kylerRenneker can you provide the full output from booting up Next.js to the error? I'm quite certain you have a .babelrc up the directory tree this means it's not in the directory that you're booting up Next.js in but actually in one of the directories above that. The cli output will show you something along the lines of "Using custom .babelrc <location>" 👍

@timneutkens I came across the same error just recently. I am in the process of migrating the creat-react-app part of my current cra/express.js setup. How do I solve this?

[ event ] build page: /next/dist/pages/_error
[ wait ]  compiling ...
[ error ] ./data/icons/amazon.png 1:0
Module parse failed: Unexpected character '�' (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
(Source code omitted for this binary file)
Error: Cannot find module '/Users/<NAME>/Projects/<PROJECTNAME>/next-ssg/.next/server/static/development/pages/_document'
Require stack:
- /Users/<NAME>/Projects/<PROJECTNAME>/next-ssg/node_modules/next/dist/next-server/server/load-components.js
- /Users/<NAME>/Projects/<PROJECTNAME>/next-ssg/node_modules/next/dist/next-server/server/api-utils.js
- /Users/<NAME>/Projects/<PROJECTNAME>/next-ssg/node_modules/next/dist/next-server/server/next-server.js
- /Users/<NAME>/Projects/<PROJECTNAME>/next-ssg/node_modules/next/dist/server/next.js
- /Users/<NAME>/Projects/<PROJECTNAME>/next-ssg/node_modules/next/dist/server/lib/start-server.js
- /Users/<NAME>/Projects/<PROJECTNAME>/next-ssg/node_modules/next/dist/cli/next-dev.js
- /Users/<NAME>/Projects/<PROJECTNAME>/next-ssg/node_modules/next/dist/bin/next
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:952:15)
    at Function.Module._load (internal/modules/cjs/loader.js:835:27)
    at Module.require (internal/modules/cjs/loader.js:1012:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at Object.loadComponents (/Users/<NAME>/Projects/<PROJECTNAME>/next-ssg/node_modules/next/dist/next-server/server/load-components.js:24:25)
    at DevServer.findPageComponents (/Users/<NAME>/Projects/<PROJECTNAME>/next-ssg/node_modules/next/dist/next-server/server/next-server.js:555:60)
    at DevServer.renderErrorToHTML (/Users/<NAME>/Projects/<PROJECTNAME>/next-ssg/node_modules/next/dist/next-server/server/next-server.js:852:33)
    at DevServer.renderErrorToHTML (/Users/<NAME>/Projects/<PROJECTNAME>/next-ssg/node_modules/next/dist/server/next-dev-server.js:19:915)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async DevServer.render (/Users/<NAME>/Projects/<PROJECTNAME>/next-ssg/node_modules/next/dist/next-server/server/next-server.js:540:22)
    at async Object.fn (/Users/<NAME>/Projects/<PROJECTNAME>/next-ssg/node_modules/next/dist/next-server/server/next-server.js:390:17)
    at async Router.execute (/Users/<NAME>/Projects/<PROJECTNAME>/next-ssg/node_modules/next/dist/next-server/server/router.js:134:32)
    at async DevServer.run (/Users/<NAME>/Projects/<PROJECTNAME>/next-ssg/node_modules/next/dist/next-server/server/next-server.js:505:29)
    at async DevServer.handleRequest (/Users/<NAME>/Projects/<PROJECTNAME>/next-ssg/node_modules/next/dist/next-server/server/next-server.js:149:20) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/Users/<NAME>/Projects/<PROJECTNAME>/next-ssg/node_modules/next/dist/next-server/server/load-components.js',
    '/Users/<NAME>/Projects/<PROJECTNAME>/next-ssg/node_modules/next/dist/next-server/server/api-utils.js',
    '/Users/<NAME>/Projects/<PROJECTNAME>/next-ssg/node_modules/next/dist/next-server/server/next-server.js',
    '/Users/<NAME>/Projects/<PROJECTNAME>/next-ssg/node_modules/next/dist/server/next.js',
    '/Users/<NAME>/Projects/<PROJECTNAME>/next-ssg/node_modules/next/dist/server/lib/start-server.js',
    '/Users/<NAME>/Projects/<PROJECTNAME>/next-ssg/node_modules/next/dist/cli/next-dev.js',
    '/Users/<NAME>/Projects/<PROJECTNAME>/next-ssg/node_modules/next/dist/bin/next'
  ]
}

Doesn't say anything about a babel.rc file though. Just for completeness sake, I actually do have a _document.js file

Also seeing this issue on my windows computer, but not on any of my Mac's 🤔

Am able to get around this by creating the next app directly on my desktop. But no idea why it doesn't work in the standard My Documents/Github/[project] location.
I have looked everywhere and didn't find a random .babelrc file anywhere. Very odd, but for now, can continue working, with my NextJS projects located in a different place than all my other projects, tad annoying.

In my case it is failing with the same error because I run the project from C:\repos\projectname, but C:\repos is a directory junction to C:\Users\Qwerty\repos. When I run npm run dev from the original directory, it worked.

This is rather a pain, but at least it works.

Related to the above comment.
By default Windows put my Github projects in
/My Documents/Github/project-name

To get around this error, I needed to instead navigate to
/documents/github/project-name
and everything worked.

Oh my god 🤦‍♂️ Thanks past myself. You helped me again!

Was this page helpful?
0 / 5 - 0 ratings