This repository was archived by the owner on Jan 28, 2025. It is now read-only.
Rewrites object format not supported #1003
Open
Description
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:
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