I am encountering an issue that is causing some frustration. The problem only arises during my github actions build. Interestingly, when I run the build locally, everything works perfectly and I can access the route handler without any issues. However, even when I try to simulate the github action locally using act and Docker, I still face the same error.
Here's the error message:
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)
The problematic file 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'});
}
I expect the build to be successful so I can access:
http://localhost:3000/api/reports?id=SOME_ID&partitionKey=SOME_KEY
However, I am getting the error mentioned above during the build process itself, not even during runtime.
Interestingly, the mentioned URL works fine when tested locally.
I have tried several solutions, such as:
- Changing the filename to
route-bad.tsx
, which surprisingly allowed the build to succeed - Removing the URL parsing, resulting in a successful build
- Using an alternate method for URL parsing with the
qs
library, but still facing the same error
I would greatly appreciate any assistance on this matter!