Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrites object format not supported #1003

Open
myrjola opened this issue Apr 16, 2021 · 9 comments
Open

Rewrites object format not supported #1003

myrjola opened this issue Apr 16, 2021 · 9 comments
Labels
enhancement New feature or request

Comments

@myrjola
Copy link

myrjola commented Apr 16, 2021

Describe the bug

The rewrites configuration also supports an object, but this does not currently work in the default Lambda. https://nextjs.org/docs/api-reference/next.config.js/rewrites

Rewrites are applied after checking the filesystem (pages and /public files) and before dynamic routes by default. This behavior can be changed by instead returning an object instead of an array from the rewrites function

Actual behavior

The default Lambda crashes with the following:

{
  "errorType": "TypeError",
  "errorMessage": "rewrites is not iterable",
  "trace": [
    "TypeError: rewrites is not iterable",
    "    at getRewritePath (/var/task/index.js:3461:27)",
    "    at handleOriginRequest (/var/task/index.js:8867:31)",
    "    at Runtime.handler$1 [as handler] (/var/task/index.js:8774:26)",
    "    at Runtime.handleOnce (/var/runtime/Runtime.js:66:25)"
  ]
}

Expected behavior

The rewrites should apply without any crash.

Steps to reproduce

Add rewrites with the object format to next.config.js:

module.exports = {
  async rewrites() {
    return {
      beforeFiles: [{
        source: '/fi/varaus',
        destination: '/fi/reservation',
        locale: false
      }]
    }
  },
}

When navigating to /fi/varaus, you will get the "rewrites is not iterable" error instead of navigating to the /pages/reservation.tsx page.

Screenshots/Code/Logs

The crash looks like this from the user's perspective:

crash image

Versions

  • OS/Environment: Deployed from Gitlab CI/CD pipeline
  • @sls-next/serverless-component version: 1.19.0-alpha.42
  • Next.js version: 10.1.3
@dphang
Copy link
Collaborator

dphang commented Apr 17, 2021

Yes it seems Next.js might have recently added rewrites object format? I didn't recall it when I first implemented rewrites. So it would need to be implemented. I'm working on some other stuff at the moment but can tag this as good first issue / enhancement in case someone wants to pick it up.

@seifeddinebesbes
Copy link

seifeddinebesbes commented Jun 23, 2021

Hello,
I would like to contribute and can i start by taking this task ?

@dphang
Copy link
Collaborator

dphang commented Jun 23, 2021

@seifeddinebesbes Yes! I think no one else is working on it at the moment. Definitely let us know if you need help to get started or you can join the slack as well (email us at serverlessnextjs@gmail.com)

@seifeddinebesbes
Copy link

@dphang thank you and i already sent you an email :) :)

Best regards,
Seif

@zburk
Copy link

zburk commented Jun 28, 2021

Having the same issue. Is there any workaround currently or is downgrading to Next 9 the best option til this is fixed?

@seifeddinebesbes
Copy link

@zburk you can use the old rewrites configuration without downgrading to Next9
for example :
image

@zburk
Copy link

zburk commented Jun 28, 2021

Are there any logs created for rewrites? I tried setting it up and keep getting a 404 error. If I deploy the exact same code to Vercel, it works fine.

@dphang dphang removed the good first issue Good for newcomers label Aug 25, 2021
@MarceloAzeved0
Copy link

Hello, i have the same error, have any updates on this issue?

@danwestonwunderman
Copy link

danwestonwunderman commented Nov 1, 2022

This is is still happening. Any news?

My scenario is trying to create a dynamic robots

async rewrites() { return { beforeFiles:[{ source: '/robots.txt', destination: '/api/robots', locale: false }] }; },

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

6 participants