next-runtime icon indicating copy to clipboard operation
next-runtime copied to clipboard

[Bug]: Next Redirects don't get persisted if `netlify build` and `netlify deploy` are run seperately

Open DavidWells opened this issue 2 years ago • 1 comments

Summary

When trying to deploy a site manually via Netlify CLI the redirects aren't persisted.

Here's what didn't work:

netlify build && netlify deploy --prod

Here's what ultimately did work:

netlify deploy --build --prod

When you run netlify build it says its adding redirects like so:

Netlify configuration property "redirects" value changed to [
  { from: '/_next/static/*', to: '/static/:splat', status: 200 },
  {
    from: '/_next/image*',
    query: { url: ':url', w: ':width', q: ':quality' },
    to: '/_ipx/w_:width,q_:quality/:url',
    status: 301
  },
  { from: '/_ipx/*', to: '/.netlify/builders/_ipx', status: 200 },
  { from: '/cache/*', to: '/404.html', status: 404, force: true },
  { from: '/server/*', to: '/404.html', status: 404, force: true },
  { from: '/serverless/*', to: '/404.html', status: 404, force: true },
  { from: '/trace', to: '/404.html', status: 404, force: true },
  { from: '/traces', to: '/404.html', status: 404, force: true },
  {
    from: '/routes-manifest.json',
    to: '/404.html',
    status: 404,
    force: true
  },
  {
    from: '/build-manifest.json',
    to: '/404.html',
    status: 404,
    force: true
  },
  {
    from: '/prerender-manifest.json',
    to: '/404.html',
    status: 404,
    force: true
  },
  {
    from: '/react-loadable-manifest.json',
    to: '/404.html',
    status: 404,
    force: true
  },
  { from: '/BUILD_ID', to: '/404.html', status: 404, force: true },
  {
    from: '/api/*',
    to: '/.netlify/functions/___netlify-handler',
    status: 200
  },
  {
    from: '/_redirects',
    to: '/_redirects',
    conditions: { Cookie: [Array] },
    status: 200
  },
  {
    from: '/*',
    to: '/.netlify/functions/___netlify-handler',
    status: 200,
    conditions: { Cookie: [Array] },
    force: true
  },
  {
    from: '/_next/data/1QYE_ME3iWBSXQ3TmbKeN/index.json',
    to: '/.netlify/functions/___netlify-handler',
    status: 200,
    force: false
  },
  {
    from: '/',
    to: '/.netlify/functions/___netlify-handler',
    status: 200,
    force: false
  },
  {
    from: '/*',
    to: '/.netlify/functions/___netlify-handler',
    status: 200
  }
].

But these aren't actually processed or saved anywhere in the build and the subsequent netlify deploy is "redirectless"

Might want to add this to the docs somewhere or make the output of the CLI more clear on what users of the plugin need to do.

This guys post saved me in the end https://paulonteri.com/thoughts/how-to/deploy-nextjs-to-netlify-manually

Steps to reproduce

Listed above

A link to a reproduction repository

No response

Next Runtime version

latest

Is your issue related to the app directory (beta)?

  • [ ] Yes, I am using the app directory

More information about your build

  • [ ] I am building using the CLI
  • [ ] I am building using file-based configuration (netlify.toml)

What OS are you using?

None

Your netlify.toml file

`netlify.toml`
# Paste content of your `netlify.toml` file here

Your public/_redirects file

`_redirects`
# Paste content of your `_redirects` file here

Your next.config.js file

`next.config.js`
# Paste content of your `next.config.js` file here. Check there is no private info in there.

Builds logs (or link to your logs)

Build logs
# Paste logs here

Function logs

Function logs
# Paste logs here

.next JSON files

generated .next JSON files
# Paste file contents here. Please check there isn't any private info in them
# You can either build locally, or download the deploy from Netlify by clicking the arrow next to the deploy time.

DavidWells avatar Mar 16 '23 00:03 DavidWells

For those looking to deploy sites locally and reset your modified netlify.toml file here is the build/deploy command I'm using:

netlify deploy --build && echo 'reset netlify.toml changes' && git checkout -- netlify.toml

DavidWells avatar Apr 06 '23 20:04 DavidWells

@DavidWells Can you confirm whether this issue still occurs with v5 of the runtime and Next.js 13.5+?

serhalp avatar Jun 04 '24 16:06 serhalp

I'm closing this since there hasn't been any activity in over a year. Feel free to start a new thread on https://answers.netlify.com/ if you need more support.

serhalp avatar Jun 12 '24 13:06 serhalp