javascript 在Vercel中部署NextJS失败

nafvub8i  于 2023-09-29  发布在  Java
关注(0)|答案(1)|浏览(137)

你好,我是Web开发的初学者。我试图在Vercel中部署我的第一个NextJS应用程序,但我总是得到这个错误。

错误:

SyntaxError: Unexpected token T in JSON at position 0
    at JSON.parse (<anonymous>)
    at parseJSONFromBytes (node:internal/deps/undici/undici:6662:19)
    at successSteps (node:internal/deps/undici/undici:6636:27)
    at node:internal/deps/undici/undici:1236:60
    at node:internal/process/task_queues:140:7
    at AsyncResource.runInAsyncScope (node:async_hooks:203:9)
    at AsyncResource.runMicrotask (node:internal/process/task_queues:137:8)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
> Build error occurred
Error: Failed to collect page data for /download/[appName]
    at /vercel/path0/Bulaloi App/next-app/node_modules/next/dist/build/utils.js:1158:15
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  type: 'Error'
}
Error: Command "npm run build" exited with 1

下载页面:

import DownloadPage from '../../components/DownloadPageComponents/DownloadPage.js'

export default function DownloadPagee({ data }) {
  return <DownloadPage data={data} />;
}

export async function getStaticProps({ params }) {
  const { appName } = params;

  // Fetch data from `/api/download/${appName}`
  const res = await fetch(`${process.env.NEXT_PUBLIC_URL}/api/download/${appName}`);
  const data = await res.json();

  return { props: { data } };
}

export async function getStaticPaths() {
  // Fetch data from `/api/apps-games/all`
  const res = await fetch(`${process.env.NEXT_PUBLIC_URL}/api/apps-games/all`);
  const data = await res.json();

  // Map each object's `appName` property to `params`
  const paths = data.map((obj) => ({
    params: { appName: obj.appName },
  }));

  return { paths, fallback: false };
}

.env变量

NEXT_PUBLIC_URL="https://bulaloi.vercel.app"

我已经尝试将.env变量更改为NEXT_PUBLIC_URL="http://bulaloi.vercel.app",但错误保持不变。我是非常新的SSG,所以我认为问题可能是在下载页面代码,请帮助我。先谢谢你了。

hjzp0vay

hjzp0vay1#

你必须给vercel添加环境变量。当你点击项目时,你会看到这个菜单:

相关问题