Netlify dev and Hugo throwing a ERR_TOO_MANY_REDIRECTS error

Hi everyone,

I’m trying to use Netlify dev with Hugo. When I run netlify dev, it works fine in the terminal but when I visit http://localhost:8888/ the browser throws an error for ERR_TOO_MANY_REDIRECTS.

I am using the following options inside of my netlify.toml:

[build]
  publish = "public"
  command = "hugo --gc && cp _redirects public/_redirects"
  functions = "./functions"

[context.branch-deploy]
  command = "hugo --gc -b && cp _redirects public/_redirects && cp _branch_headers public/_headers"
  functions = "./functions"

[dev]
  framework = "#custom"
  command = "hugo serve && cp _redirects public/_redirects"
  targetPort = 1313
  publish = "public"
  autoLaunch = true

Here’s a screenshot of everyone:

Does anyone know how to fix this?

Thanks,

Dave.

Just as a quick update, if I remove all of the [dev] settings it works fine but doesn’t live update. I assume that’s because it uses the default build command which is a one time thing rather than watching for changes.

Cheers!

What’s the code in your _redirects?

Also, from what I know, Netlify automatically detects the presence of special files like _redirects, _headers and netlify.toml in the root folder and you might not have to copy it after build. I said so because that’s how it works in the online build, so I would expect Netlify Dev (I haven’t used it myself) to behave in the same way. Apologies if I’m wrong.

Hi

I have the same issue. netlify dev sets up fine, but there is an error in the browser. I have a redirects file, but nothing changes if I remove it.

netlify-cli/2.69.0 darwin-x64 node-v12.6.0

[build]
  publish = "public"
  functions = "functions"
  command = "hugo"

[build.environment]
  HUGO_VERSION = "0.79.0"
  HUGO_ENV = "production"
  HUGO_ENABLEGITINFO = "true"
  GIT_LFS_ENABLED = "true"

What’s the error in browser?

I have the same error as daveredfern: ERR_TOO_MANY_REDIRECTS

It kinda works with netlify-cli/2.50.0. Kinda because localhost:1313/style.css is blocked by cors. But there is no error in the browser

Can you check the Network tab in Developer tools to track the redirect loop, as in what’s redirecting to what and so on…?

Hi @martinjagodic.

What’s the code in your _redirects ?

Quite a lot but mostly old WordPress URLs from when we transitions. They’re all basic redirects. I assume if those work fine on the live and staging websites they should work fine on netlify dev?

Thanks

Yes, that’s a correct assumption. Just like @martinjagodic said, does using that version help?

Screenshot of the network tab. I hope it helps.

Looks like it’s just redirecting the index.html back to the index.html in a continuous loop. Might be a bug?. If you have the time, can you check if changing (upgrading/downgrading) versions helps?

EDIT: Also, a live issue is here: Standard 404 rule causes infinite redirect when running static Hugo site with dev command · Issue #1595 · netlify/cli · GitHub.

Almost identical for me as @martinjagodic.

If I use the normal one-off Hugo build it’s fine. As soon as I try to use hugo server it goes into a redirect loop.

Looks like it’s just redirecting the index.html back to the index.html in a continuous loop. Might be a bug?. If you have the time, can you check if changing (upgrading/downgrading) versions helps?

I’m happy to try this. Is there any documentation on how to downgrade and upgrade, please? I can’t see any on the Github pages.

Thanks!

Well, it’s nothing specific to Netlify. You can use simple NPM install commands:

Check the versions here: netlify-cli - npm

And then, npm install -g netlify-cli@2.69.3 (or any other version)

You should probably uninstall the current version thoug:

npm uninstall -g netlify-cli

@daveredfern you can install a specific version via npm with npm i -g netlify-cli@2.50.0.

I tried a few versions and indeed 2.50.0 is the last one where it works (I didn’t try minor versions.).

So it seems like you’d have to probably stick to 2.50.0 for now.

However, about @martinjagodic’s CORS error, are you using relative URLs or absolute? If you’re using absolute, try switching to relative ones.

@hrishikesh thanks for the bonus tip, I had to use href="{{ $style.RelPermalink }}" instead of href="{{ $style.Permalink }}"

Will stick to 2.50.0 for now, thanks for your help.

1 Like