Netlify dev issue while build/deploy is working

Hello folks!

I’m having a weird issue in a nextjs project, this is what I’ve found:

  • Running netlify build and deployment (branch commit) works well
  • Running npm run dev works well
  • Running netlify dev and navigating from my home page through Link to my /login page works correctly.
  • Running netlify dev and trying to load my /login page directly doesn’t work (details below)

What I’ve done:

  • Deleted both the “out” and “.next” folders and built again
  • Checked the network response for the html file and it doesn’t match the login.html in the out folder
  • The page throws me an error “Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 0”
  • I even tried changing my page name to “account.js” still has the same issue
  • I’ve stripped all logic of that page to having just a “hello world” only and it still serves this old html version

Seems like some weird caching problem, but I have no idea how to fix it. Help would be much appreciated :slight_smile:

Hi @pertoi,

Just to confirm this caching issue only happens locally?

If yes, could you try without netlify dev, or a different device/browser?

It only happens locally, same happens on other browsers (safari, firefox). Works correctly with “npm run dev” (port: 3000).

@hrishikesh thanks for the help!

This works well:
netlify dev --dir=out

I’ve tried adding this to the netlify.toml file:

[dev]
  publish = "out"

but with no success. :frowning: Seems the netlify dev is reading from some weird folder.

Fixed it by adding a “/”

[dev]
  publish = "/out"

However, I’m still curious, what’s the default publish folder?

I have the same folder on build:

[build]
  publish = "out"

That’s weird, because from my understanding, publish folder should have not have any technical effect on this. I don’t think any SSG actually renders the development build to the publish folder. I know one - Hugo, that does it if you explicitly ask it to, not otherwise. So, the development server never really reads files from the publish folder.

But even if it does, I don’t see how it would affect caching. Are you clearing the contents of the out folder before starting the server?

At least intentionally I’m not clearing the contents of the folder. When I was trying to find the issue, I did it once or twice, with no success on solving the problem.

If it doesn’t read from the /out folder, how does it render the components? Really newbie here :slight_smile:

That’s interesting. I had seen a similar case but it was a Hugo website. Check it out here:

Netlify CLI sets up a proxy to your SSG’s development server, which is why it starts 2 servers - your SSG’s development server and it’s own server. The ‘own’ server takes the request → sends it to the SSG’s server → receives a response from there → sends it back to the original requestor (in most cases the browser). So, I don’t think NextJS renders the content to the out folder when you run its development server which is why I said, that’s not from where CLI is reading the content.

1 Like