0

I am receiving the following build error when doing "vercel build" and have tried changing the vercel directory, setting CI to false, checked for the fetch failed type error. I have removed and reinstalled the node modules. I think it may be that vercel cant access some files. I am connected to the sanity.io CMS backend using fetch and updating the website via their CMS.

https://github.com/Jameshunter1/Portfolio

C:\Users\James\OneDrive\Desktop\Web Dev Projects\portfolio-james>vercel build Vercel CLI 28.4.4 WARNING: You should not upload the .next directory. Installing dependencies...

up to date in 2s

216 packages are looking for funding run npm fund for details Detected Next.js version: 12.3.0 Detected package-lock.json generated by npm 7+... Running "npm run build"

portfolio-james@0.1.0 build next build

info - Loaded env from C:\Users\James\OneDrive\Desktop\Web Dev Projects\portfolio-james.env.local info - Linting and checking validity of types info - Creating an optimized production build info - Compiled successfully info - Collecting page data [== ] info - Generating static pages (2/3)(node:8760) ExperimentalWarning: The Fetch API is an experimental feature. This feature could change at any time (Use node --trace-warnings ... to show where the warning was created)

Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error TypeError: fetch failed at Object.processResponse (node:internal/deps/undici/undici:6254:34) at node:internal/deps/undici/undici:6579:42 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) info - Generating static pages (3/3)

Build error occurred Error: Export encountered errors on following paths: / at C:\Users\James\OneDrive\Desktop\Web Dev Projects\portfolio-james\node_modules\next\dist\export\index.js:394:19 at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async Span.traceAsyncFn (C:\Users\James\OneDrive\Desktop\Web Dev Projects\portfolio-james\node_modules\next\dist\trace\trace.js:79:20) at async C:\Users\James\OneDrive\Desktop\Web Dev Projects\portfolio-james\node_modules\next\dist\build\index.js:1168:21 at async Span.traceAsyncFn (C:\Users\James\OneDrive\Desktop\Web Dev Projects\portfolio-james\node_modules\next\dist\trace\trace.js:79:20) at async C:\Users\James\OneDrive\Desktop\Web Dev Projects\portfolio-james\node_modules\next\dist\build\index.js:1044:17 at async Span.traceAsyncFn (C:\Users\James\OneDrive\Desktop\Web Dev Projects\portfolio-james\node_modules\next\dist\trace\trace.js:79:20) at async Object.build [as default] (C:\Users\James\OneDrive\Desktop\Web Dev Projects\portfolio-james\node_modules\next\dist\build\index.js:65:29) Error: Command "npm run build" exited with 1

**package.json**

{
  "name": "portfolio-james",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "lint": "next lint"
  },
  "dependencies": {
    "@heroicons/react": "^2.0.11",
    "@portabletext/react": "^1.0.6",
    "@sanity/image-url": "^1.0.1",
    "firebase": "^9.10.0",
    "framer-motion": "^7.3.5",
    "next": "^12.3.0",
    "next-sanity": "^0.8.4",
    "react": "^18.2.0",
    "react-dom": "18.2.0",
    "react-hook-form": "^7.36.0",
    "react-simple-typewriter": "^4.0.2",
    "react-social-icons": "^5.14.0"
  },
  "devDependencies": {
    "@types/node": "18.7.18",
    "@types/react": "18.0.20",
    "@types/react-dom": "18.0.6",
    "autoprefixer": "^10.4.11",
    "eslint": "8.23.1",
    "eslint-config-next": "12.3.0",
    "postcss": "^8.4.16",
    "tailwind-scrollbar": "^2.0.1",
    "tailwindcss": "^3.1.8",
    "typescript": "4.8.3"
  }
}

**/.vercel/builds.json/**

**"//": "This file was generated by the `vercel build` command. It is not part of the Build 
  Output API.",
  "target": "preview",
  "argv": [
    "C:\\Program Files\\nodejs\\node.exe",
    "C:\\Users\\James\\AppData\\Roaming\\npm\\node_modules\\vercel\\dist\\index.js",
    "build"
  ],
  "builds": [
    {
      "require": "@vercel/next",
      "requirePath": "C:\\Users\\James\\AppData\\Roaming\\npm\\node_modules\\vercel\\node_modules\\@vercel\\next\\dist\\index",
      "apiVersion": 2,
      "src": "package.json",
      "use": "@vercel/next",
      "config": {
        "zeroConfig": true,
        "framework": "nextjs"
      },
      "error": {
        "name": "Error",
        "stack": "Error: Command \"npm run build\" exited with 1\n    at ChildProcess.<anonymous> (C:\\Users\\James\\AppData\\Roaming\\npm\\node_modules\\vercel\\node_modules\\@vercel\\build-utils\\dist\\index.js:30910:20)\n    at ChildProcess.emit (node:events:513:28)\n    at ChildProcess.emit (node:domain:482:12)\n    at ChildProcess.cp.emit (C:\\Users\\James\\AppData\\Roaming\\npm\\node_modules\\vercel\\node_modules\\@vercel\\build-utils\\dist\\index.js:17913:29)\n    at maybeClose (node:internal/child_process:1091:16)\n    at Process.ChildProcess._handle.onexit (node:internal/child_process:302:5)",
        "message": "Command \"npm run build\" exited with 1",
        "hideStackTrace": true,
        "code": "BUILD_UTILS_SPAWN_1"
      }
    }
  ],
  "error": {
    "name": "Error",
    "stack": "Error: Command \"npm run build\" exited with 1\n    at ChildProcess.<anonymous> (C:\\Users\\James\\AppData\\Roaming\\npm\\node_modules\\vercel\\node_modules\\@vercel\\build-utils\\dist\\index.js:30910:20)\n    at ChildProcess.emit (node:events:513:28)\n    at ChildProcess.emit (node:domain:482:12)\n    at ChildProcess.cp.emit (C:\\Users\\James\\AppData\\Roaming\\npm\\node_modules\\vercel\\node_modules\\@vercel\\build-utils\\dist\\index.js:17913:29)\n    at maybeClose (node:internal/child_process:1091:16)\n    at Process.ChildProcess._handle.onexit (node:internal/child_process:302:5)",
    "message": "Command \"npm run build\" exited with 1",
    "hideStackTrace": true,
    "code": "BUILD_UTILS_SPAWN_1"
  }
}**
  • Does the dev server start without errors? (npm run dev) – maxeth Sep 28 '22 at 21:00
  • yes it runs perfect locally with no warnings or errors, I'm adding the GitHub repo I pushed it to for more clarity – James Hunter Sep 28 '22 at 21:06
  • 1
    Just took a look, and it seems like you're calling your api inside ```getStaticProps```on index.tsx for example, but ```getStaticProps``` is executed at build-time, so the API "isn't there yet" because - unlike in dev mode - the server isn't running yet during ```getStaticProps``` execution. You can directly copy/perform the logic from the api routes inside ```getStaticProps``` instead of calling them. Let me know if it works :) – maxeth Sep 28 '22 at 21:28
  • What @maxeth above said. See [Fetch error when building Next.js static website in production](https://stackoverflow.com/questions/66202840/fetch-error-when-building-next-js-static-website-in-production). – juliomalves Oct 03 '22 at 16:40

1 Answers1

0

dot env file can be the problem, add your all environment variables in vercel project settings.

Or create one more .env.production and copy-paste the env local data to it.

Sahil Popli
  • 1,967
  • 14
  • 21