I am getting the error below, and spinning wheels figuring it out. It only happens during my github actions build. When I run the build locally, it works fine and I can hit the route handler. I can also run the github action locally using act and Docker, and then I get the error as well.
Here's the error:
TypeError [ERR_INVALID_URL]: Invalid URL
at new NodeError (node:internal/errors:405:5)
at new URL (node:internal/url:676:13)
at new ni (/home/runner/work/frontend/.next/server/app/api/reports/route.js:6:40210)
And the file in question is src/app/api/reports/route.tsx:
export async function GET(request: Request) {
const { searchParams } = new URL(request.url); // <- here is the problem
const id = searchParams.get('id');
const partitionKey = searchParams.get('partitionKey');
if (!id || !partitionKey) {
return NextResponse.json({msg: 'Success'});
}
The result I expect is that the build completes and I can hit:
http://localhost:3000/api/reports?id=SOME_ID&partitionKey=SOME_KEY
And get a result. The actual result is the error above, during build time (not even runtime).
When I run it locally, the URL above works.
I have tried a ton, including:
- I changed the name of the file to
route-bad.tsxand the build succeeds - I took out the URL parsing and the build succeeds.
- I tried an alternate form of build parsing the just uses strings and the
qslibrary. I still get the error.
Any help is appreciated!
You need to proppelly include the url start different ways URL://www Www.skaj.dom HTTP://www etc.