Closed
Description
Summary
Next.js throws an error when hostname
and port
are not provided in the custom server since v12.0.5-canary.18 — as a result it breaks middleware in Netlify:
// For middleware to "fetch" we must always provide an absolute URL
const url = getRequestMeta(params.request, '__NEXT_INIT_URL')!
if (!url.startsWith('http')) {
throw new Error(
'To use middleware you must provide a `hostname` and `port` to the Next.js Server'
)
}
Steps to reproduce
- Fork this simple Next.js app (
npx create-next-app
with one middleware) https://github.com/ivorpad/repro-nextjs-middleware - Deploy to Netlify
- Go to
/api/users
- Watch the
___netlify-handler
function logs
A link to a reproduction repository
https://github.com/ivorpad/repro-nextjs-middleware
Plugin version
4.2.0
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?
No response
Your netlify.toml file
`netlify.toml`
[build]
command = "npm run build"
functions = "out_functions"
publish = ".next"
[[plugins]]
package = "@netlify/plugin-nextjs"
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.