在 github 操作构建期间将 next.js 应用程序部署到 Azure 静态 Web 应用程序时出现 INVALID_URL

问题描述 投票:0回答:1

我收到下面的错误,并且旋转轮子解决了这个问题。它只发生在我的 github actions 构建期间。当我在本地运行构建时,它工作正常,我可以点击路由处理程序。我还可以使用 act 和 Docker 在本地运行 github 操作,然后我也收到错误。

这是错误:

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)

有问题的文件是

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'});
  }

我期望的结果是构建完成,我可以点击:

http://localhost:3000/api/reports?id=SOME_ID&partitionKey=SOME_KEY

并得到结果。实际结果是上面的错误,在构建期间(甚至不是运行时)。

当我在本地运行它时,上面的 URL 可以工作。

我尝试了很多,包括:

  1. 我将文件名更改为
    route-bad.tsx
    ,构建成功了
  2. 我把URL解析拿出来,构建成功了。
  3. 我尝试了另一种构建解析形式,仅使用字符串和
    qs
    库。我仍然收到错误。

如有任何帮助,我们将不胜感激!

typescript next.js github-actions azure-static-web-app
1个回答
0
投票

您需要以不同的方式包含 url 开头 URL://www 斯卡吉网站 HTTP://www 等

© www.soinside.com 2019 - 2024. All rights reserved.