next.js: Hot reload not working at latest version of Next.js

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
      Platform: darwin
      Arch: arm64
      Version: Darwin Kernel Version 22.5.0: Mon Apr 24 20:53:44 PDT 2023; root:xnu-8796.121.2~5/RELEASE_ARM64_T8103
    Binaries:
      Node: 18.16.0
      npm: 9.5.1
      Yarn: 1.22.19
      pnpm: 8.5.1
    Relevant packages:
      next: 13.4.5-canary.12
      eslint-config-next: 13.4.5
      react: 18.2.0
      react-dom: 18.2.0
      typescript: 5.1.3

Which area(s) of Next.js are affected? (leave empty if unsure)

No response

Link to the code that reproduces this issue or a replay of the bug

To Reproduce

  1. npx create-next-app@latest (next-tw)
  2. yarn install
  3. yarn dev

Describe the Bug

main-app.js:1425 Uncaught TypeError: __webpack_require__.ts is not a function
    at (app-client)/./node_modules/next/dist/compiled/@next/react-refresh-utils/dist/runtime.js

Expected Behavior

Hot reload should work

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 50
  • Comments: 75 (8 by maintainers)

Most upvoted comments

So I got a fix for mine. I think the hot reload works. If you are working with WSL2 on Windows, ensure you move your next folders or app to the home <your_name>:/home$ directory.

In fact, it has nothing to do with NextJs in my case. The next app was in the mnt/c <your_name>:/mnt/c$ folders was what made the HMR not work.

Just like to chime in. I was on node v16.13.1 and nextjs 13.4.19

Problems:

  • hot reload not working, like OP
  • clicking links reloads the whole page
  • annoying “ExperimentalWarning: stream/web is an experimental feature. This feature could change at any time” in console

I just updated node version to v18.17.1 and all those problems went away.

@weyert not working for me as of 13.4.19

@leerob

Would you mind taking a look at this please? It’s really killing dev productivity…(and is very frustrating since we’ve been spoiled with a super awesome HMR prior to this)

Would appreciate it so much!

For me this bug was caused by having assetPrefix: "http://localhost:3000" in my next.config.js and I fixed it by changing it to assetPrefix: undefined.

4 days. Is it just me but the current npx create-next-app@latest is broken. It does not refresh on editing and a simple not-found leaves a blank page. Can someone please confirm that this is true. before i loose my marbles.

This is straight out the box, no custom servers - no nothing?

Could everyone please provide their environment info similar to the original issue? And what is the last version it is working for you?

Hey, I think many people are facing this issue, because of the node version. Like me, i was using node v16.3 in nvm as default. but nextjs docs says it needs atleast 16.4. Since i didn’t get any errors during my setup, i forgot to change my node version. but then later i got this issue when is started to code. since i was using default setup from the docs itself, i immediately realised its the node issue. I switched to node 20 and its working very smoothly.

maybe as in the docs, if there is a way to check the node version during development, its better to throw an error/warning to update node version.

HMR still not working in Google Chrome or Brave using Next 13.5.6 on Windows 11

I just found out my problem was not due to the next.js version but a problem in my layout.tsx.

The issue was in my layout.tsx file that was causing hydration / mounting issues because of a dom mismatch.

Here is the exact section from documentation

The root layout must define <html> and <body> tags since Next.js does not automatically create them.

Additionally, don’t put any Wrapper Element outside body tag like this:

   <AuthProvider>
    <body>
          {children}
     </body>
   </AuthProvider>

but make sure that body tag always includes all components

<body>
   <AuthProvider>
      {children}
  <AuthProvider>
</body>

Hope it helps!

I have the same problem. It would be nice if the hot reloading script would throw more logs, so we knew why it’s happening.

This happened to me too. It was fixed by removing the metadata export in layout.tsx generated by the npx script, since that’s a non-react component export, presumably.

import type { Metadata } from "next";
import { Inter } from "next/font/google";
import "./globals.css";

const inter = Inter({ subsets: ["latin"] });

// export const metadata: Metadata = {
//   title: "Create Next App",
//   description: "Generated by create next app",
// };

export default function RootLayout({
  children,
}: Readonly<{
  children: React.ReactNode;
}>) {
  return (
    <html lang="en">
      <body className={inter.className}>{children}</body>
    </html>
  );
}

Not working for me. node 20.10.0 & next 14.0.4. I can see the [Fast Refresh] rebuilding on the browser, but nothing happens.

Screenshot 2023-12-22 at 7 19 14 AM

Hey, guys. I also have this problem on the latest version. I switched to version 13.4.15 and that helped me.

It looks like this MR broke it when using assetPrefix: https://github.com/vercel/next.js/pull/59471

Most likely the issue would be related to import or export statement.

Correct casing of the import statements is very important, Notice the casing of letter “H” in the “heroSection”.

import HeroSection from "@/components/pageComponents/HeroSection";

import HeroSection from "@/components/pageComponents/heroSection";

Not sure why but I also have issue with hot reload. In the browser I see [Fast Refresh] rebuilding but dom is never updated. Any changes to the code require hard reload - basically not able to develop with such performance.

"next": "^14.0.4",

"devDependencies": {
    "@types/bcrypt": "^5.0.2",
    "autoprefixer": "^10.4.16",
    "postcss": "^8.4.33",
    "tailwindcss": "^3.4.1"
  }

node 20.11

Spent probably three hours trying to find my bug. HMR did not work. I have a pages directory and an app directory (Migrating from pages to app). Deleted my metadata export, font and CSS on my app layout. Relaunch the dev server. Hard reload.

Boom it works!

Now to pinpoint the problem.

Edit: It is not the metadata. Edit 2: Not the font. Guess it’s a problem with globals CSS import? Edit 3: The CSS import in the layout.tsx causes changes in files to full-reload.

I have no fix.

Here is my repo: https://github.com/Skippou/next-dynamic-test/tree/HMRnotWorking

  Platform: win32
  Arch: x64
  Version: Windows 11 Pro
Binaries:
  Node: 20.9.0
  npm: N/A
  Yarn: N/A
  pnpm: N/A
Relevant Packages:
  next: 14.0.4-canary.9
  eslint-config-next: 14.0.2
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.2.2
Next.js Config:
  output: N/A

Edit 4: It works if I downgrade to NextJS 13.2 as suggested in: https://github.com/vercel/next.js/issues/57046#issue-1951896689

Having this problem too on my mac. I’ve been trying to swap node versions (v16.20.2, v20.9.0, v21.1.0) and none of them worked for me.

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 23.1.0: Mon Oct  9 21:32:11 PDT 2023; root:xnu-10002.41.9~7/RELEASE_ARM64_T6030
Binaries:
  Node: 16.20.2
  npm: 8.19.4
  Yarn: N/A
  pnpm: 8.10.2
Relevant Packages:
  next: 14.0.1
  eslint-config-next: 14.0.1
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.2.2
Next.js Config:
  output: N/A

@devjiwonchoi Yes my comment specify to move the application to native path(WSL2) nothing more than that with respect to my comment

@ThanhHung2112 @MdSadiqMd @CassWindred @kelvinsekx Just to confirm, all WSL2 issue in this thread is about path difference right? Is there anything I need to dig in on that related to Next.js?

It has nothing to do with NextJS so don’t dig it I would say.

If you are working with WSL2, work in your home directory. In fact, for other projects that isn’t Next related, I encountered same experience, and switching paths did justice.

This is happening to me too. It’s not every time but it’s enough of the time to make it really annoying and slow down my productivity!

next: 14.2.3 npm: 10.8.1 node: 20.11.1

I was coding on other projects 2 weeks ago and it was working fine. Took a weeks break then came back this week and it’s not working…

Not working for me. Node 20.10.0 & Next 14.0.4 for .tsx files only. (It also failed with Next 12 and 13) and React 17 and 18. However changes to SCSS files for CSS modules refreshing normally. I even get the message on the browser [Fast Refresh] done in 196ms. But the DOM is never updated. I’m using localized static generation (output: export) with getStaticProps and getStaticPaths as described in this official guide

For me updating the node version to the latest fixes the issue, before I was using node version 18.16.0 now it’s 20.9.0

HMR still not working in Google Chrome or Brave using Next 13.5.6 on Windows 11

HMR still not working in Firefox 118.0.2 using Next 13.5.6 on MacOS 14.0

Testing not-found.js on a fresh build also just returns a blank page. Everything worked in 13.4.2 when I test it.

I’m glad you found a solution for yours.

I’m not using wsl2 but mine performs full reload for almost every change. Even file saves without any changes causes a full reload.

Hi @devjiwonchoi we are not using CDN

Here is our, now working config:

  // Set assetPrefix to our public URL
  // Checking for inDevelopment as '/' breaks Hot Module Reloading if used during development
  assetPrefix: inDevelopment ? undefined : '/',

encountered same issue, setting assetPrefix to undefined in dev mode solved it

For WSL2, some case you cd to path home/UserName/win-home/Desktop .... but the project stills working at /mnt/c/... path. Create the project at /home/Username/PJ_folder/ will solve this.

So I’m having the same problem and it’s definitely a WSL2 thing for me - it works fine from Powershell but Powershell bad, I have copied the project into my WSL2 home dir so no symlinks and identical files.

I’m on the latest version of NextJS and Node, both instances function identically except that when run from WSL2 it seems not to watch or hot-reload any saved changes, requiring a full stop and restart every time. I guess I’ll put up with having to use Powershell for now but would be great if there was a way to solve this.

I started on NextJS 13.5 and Node 16 but have updated each thing independently and tested across both environments, as well as trying all the applicable solutions given in this thread, but HMR continues to fail - accessing pages for the first time after a reload always produces the log Fast Refresh had to perform a full reload. Read more: https://nextjs.org/docs/messages/fast-refresh-reload.

I’m pretty sure our code is not the issue here given that it works fine when run in Windows over WSL.

In my case I had multiple exports in one of the /pages files (an object with mock data). I noticed the full page reloads, did a bunch of googling and found this thread among others. At first I thought it was because of potentially buggy Turbopack but then a warning in the terminal gave me a clue and eventually led me to the docs (first bullet point).

This also breaks HMR @ next.js <=14.1.4 and 14.2.0-canary.59:

// app/page.tsx
"use client"; // Removing the use client directive activates HMR again.

export const runtime = "edge";

export default function Home() {
  return <main>App</main>;
}

@samivagyok-web I faced the same problem but with a 13.5.4 version. It turns out it was a typo in one of my imports from a page, just like @Sumansourabh14 pointed out. So, I’d suggest you to double check your imports.

In my case, it was because I had two non-component exports in a component file.

I am using NextJS 14.1.0 and I face the same issue. However in my case,

import HeroSection from '@/components/sections/Hero';
import ServicesSection from '@/components/sections/Services';

[!note] Hot Reload works with import like this.



import { HeroSection, ServicesSection } from '@/sections';

[!warning] Hot Reload doesn’t work for import like this.

The following worked for me.

I had to create a nodemon.json file in my root directory with the following content:

{
  "verbose": true,
  "ignore": ["node_modules", ".next"],
  "watch": ["server/**/*", "index.js"],
  "ext": "js json"
}

After this, my Next.js app started reloading after any change made in the app.

Version:

"next": "14.1.0" "node": "18.17.0"

I was unable to reproduce using your steps. However, I am having this issue with my own project which started in v13.3.0. I was able to narrow it down to an issue around the custom server. Removing this server resolved my issue.

Looks like custom servers also impact some other performance optimizations (see below from the documentation).

Good to know:

  • Before deciding to use a custom server, please keep in mind that it should only be used when the integrated router of Next.js can’t meet your app requirements. A custom server will remove important performance optimizations, like serverless functions and Automatic Static Optimization.
  • A custom server cannot be deployed on Vercel.

I’ll be working on my own workaround without a custom server.

Hopefully this helps!