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
- npx create-next-app@latest (next-tw)
- yarn install
- 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)
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.1and nextjs13.4.19Problems:
I just updated node version to
v18.17.1and 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 mynext.config.jsand I fixed it by changing it toassetPrefix: 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?
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.
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
Additionally, don’t put any Wrapper Element outside body tag like this:
but make sure that body tag always includes all components
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.
Not working for me.
node 20.10.0&next 14.0.4. I can see the[Fast Refresh] rebuildingon the browser, but nothing happens.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",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
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.
@devjiwonchoi Yes my comment specify to move the application to native path(WSL2) nothing more than that with respect to my comment
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.4for.tsxfiles 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) withgetStaticPropsandgetStaticPathsas described in this official guideFor 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:
encountered same issue, setting assetPrefix to undefined in dev mode solved it
For
WSL2, some case you cd to pathhome/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
/pagesfiles (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:
@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
exportsin a component file.I am using
NextJS 14.1.0and I face the same issue. However in my case,The following worked for me.
I had to create a
nodemon.jsonfile in my root directory with the following content: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).
I’ll be working on my own workaround without a custom server.
Hopefully this helps!