Search code examples
javascriptreactjsnext.js

Next.js not auto refreshing


I'm having trouble with Next.js, basically it doesn't auto refresh local host index page whenever I make a change.

I created a Next.js app using npx create-next-app --use-npm. I started the local server using npm start, then I edited the h1 tag in index.js file, changing it from <h1>First Page</h1> to <h1>Second Page</h1>. Then I saved the file.

However, my local serve doesn't auto refresh and reflect the change I just made. I have to run npm run build then npm run start to be able to see the change.

Appreciate any suggestions, or maybe point me to the right direction on solving this, cuz not be able to see the auto refresh really slows down the dev process :(


Solution

  • You have to use npm run dev

    These scripts refer to the different stages of developing an application:

    dev - Runs next dev which starts Next.js in development mode

    build - Runs next build which builds the application for production usage

    start - Runs next start which starts a Next.js production server

    source: https://nextjs.org/docs/getting-started