My netlify site connected to sanity wont deploy

I decided to use sanity as a CMS for my portfolio site with dynamic pages, but I keep getting errors on deployment. It looks like it wont deploy because of undefined data from sanity, but the console logs the sanity data.

Full error log:

1:22:25 AM: build-image version: 4c0c1cadee6a31c9bb8d824514030009c4c05c6a (focal)
1:22:25 AM: build-image tag: v4.15.0
1:22:25 AM: buildbot version: cc0c986a947e274d444f48f63f797a5d01f2a89a
1:22:25 AM: Fetching cached dependencies
1:22:25 AM: Failed to fetch cache, continuing with build
1:22:25 AM: Starting to prepare the repo for build
1:22:25 AM: No cached dependencies found. Cloning fresh repo
1:22:25 AM: git clone https://github.com/debdevs/debdevs-portfolio
1:22:26 AM: Preparing Git Reference refs/heads/sanity-test-branch
1:22:26 AM: Parsing package.json dependencies
1:22:27 AM: Different build command detected, going to use the one specified in the Netlify configuration file: 'next build && next export' versus 'next build' in the Netlify UI
1:22:27 AM: Section completed: initializing
1:22:27 AM: Starting build script
1:22:27 AM: Installing dependencies
1:22:27 AM: Python version set to 2.7
1:22:28 AM: v16.18.1 is already installed.
1:22:28 AM: Now using node v16.18.1 (npm v8.19.2)
1:22:28 AM: Enabling node corepack
1:22:28 AM: Started restoring cached build plugins
1:22:28 AM: Finished restoring cached build plugins
1:22:28 AM: Attempting ruby version 2.7.2, read from environment
1:22:29 AM: Using ruby version 2.7.2
1:22:29 AM: Using PHP version 8.0
1:22:29 AM: No npm workspaces detected
1:22:29 AM: Started restoring cached node modules
1:22:29 AM: Finished restoring cached node modules
1:22:29 AM: Installing NPM modules using NPM version 8.19.2
1:22:35 AM: npm WARN deprecated source-map-url@0.4.1: See https://github.com/lydell/source-map-url#deprecated
1:22:35 AM: npm WARN deprecated source-map-resolve@0.5.3: See https://github.com/lydell/source-map-resolve#deprecated
1:22:36 AM: npm WARN deprecated querystring@0.2.0: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
1:22:36 AM: npm WARN deprecated uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
1:22:36 AM: npm WARN deprecated w3c-hr-time@1.0.2: Use your platform's native performance.now() and performance.timeOrigin.npm WARN deprecated topo@2.0.2: This version has been deprecated in accordance with the hapi support policy (hapi.im/support). Please upgrade to the latest version to get the best features, bug fixes, and security patches. If you are unable to upgrade at this time, paid support is available for older versions (hapi.im/commercial).
1:22:36 AM: npm WARN deprecated stable@0.1.8: Modern JS already guarantees Array#sort() is a stable sort, so this library is deprecated. See the compatibility table on MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#browser_compatibility
1:22:36 AM: npm WARN deprecated request-promise-native@1.0.9: request-promise-native has been deprecated because it extends the now deprecated request package, see https://github.com/request/request/issues/3142
1:22:37 AM: npm WARN deprecated sane@2.5.2: some dependency vulnerabilities fixed, support for node < 10 dropped, and newer ECMAScript syntax/features added
1:22:38 AM: npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
1:22:38 AM: npm WARN deprecated left-pad@1.3.0: use String.prototype.padStart()
1:22:38 AM: npm WARN deprecated kleur@2.0.2: Please upgrade to kleur@3 or migrate to 'ansi-colors' if you prefer the old syntax. Visit <https://github.com/lukeed/kleur/releases/tag/v3.0.0\> for migration path(s).
1:22:38 AM: npm WARN deprecated uglify-es@3.3.9: support for ECMAScript is superseded by `uglify-js` as of v3.13.0
1:22:39 AM: npm WARN deprecated hoek@4.2.1: This version has been deprecated in accordance with the hapi support policy (hapi.im/support). Please upgrade to the latest version to get the best features, bug fixes, and security patches. If you are unable to upgrade at this time, paid support is available for older versions (hapi.im/commercial).
1:22:39 AM: npm WARN deprecated har-validator@5.1.5: this library is no longer supported
1:22:39 AM: npm WARN deprecated html-webpack-plugin@4.0.0-alpha.2: please switch to a stable version
1:22:39 AM: npm WARN deprecated flatten@1.0.3: flatten is deprecated in favor of utility frameworks such as lodash.
1:22:39 AM: npm WARN deprecated joi@11.4.0: This version has been deprecated in accordance with the hapi support policy (hapi.im/support). Please upgrade to the latest version to get the best features, bug fixes, and security patches. If you are unable to upgrade at this time, paid support is available for older versions (hapi.im/commercial).
1:22:39 AM: npm WARN deprecated svgo@1.3.2: This SVGO version is no longer supported. Upgrade to v2.x.x.
1:22:40 AM: npm WARN deprecated circular-json@0.3.3: CircularJSON is in maintenance only, flatted is its successor.
1:22:40 AM: npm WARN deprecated acorn-dynamic-import@3.0.0: This is probably built in to whatever tool you're using. If you still need it... idknpm WARN deprecated babel-eslint@9.0.0: babel-eslint is now @babel/eslint-parser. This package will no longer receive updates.
1:22:41 AM: npm WARN deprecated chokidar@2.1.8: Chokidar 2 does not receive security updates since 2019. Upgrade to chokidar 3 with 15x fewer dependencies
1:22:41 AM: npm WARN deprecated chokidar@2.1.8: Chokidar 2 does not receive security updates since 2019. Upgrade to chokidar 3 with 15x fewer dependencies
1:22:42 AM: npm WARN deprecated eslint-loader@2.1.1: This loader has been deprecated. Please use eslint-webpack-plugin
1:22:43 AM: npm WARN deprecated chokidar@2.1.8: Chokidar 2 does not receive security updates since 2019. Upgrade to chokidar 3 with 15x fewer dependencies
1:22:44 AM: npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
1:22:44 AM: npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
1:22:46 AM: npm WARN deprecated core-js@2.6.12: core-js@<3.23.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Some versions have web compatibility issues. Please, upgrade your dependencies to the actual version of core-js.
1:22:46 AM: npm WARN deprecated core-js@2.6.4: core-js@<3.23.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Some versions have web compatibility issues. Please, upgrade your dependencies to the actual version of core-js.
1:22:51 AM: added 2477 packages, and audited 2478 packages in 21s
1:22:51 AM: 134 packages are looking for funding
1:22:51 AM:   run `npm fund` for details
1:22:51 AM: 72 vulnerabilities (12 low, 19 moderate, 37 high, 4 critical)
1:22:51 AM: To address issues that do not require attention, run:
1:22:51 AM:   npm audit fix
1:22:51 AM: To address all issues (including breaking changes), run:
1:22:51 AM:   npm audit fix --force
1:22:51 AM: Run `npm audit` for details.
1:22:51 AM: NPM modules installed
1:22:51 AM: Creating package sha
1:22:51 AM: Started restoring cached go cache
1:22:51 AM: Finished restoring cached go cache
1:22:52 AM: Installing Go version 1.19.4 (requested 1.19.x)
1:22:57 AM: unset GOOS;
1:22:57 AM: unset GOARCH;
1:22:57 AM: export GOROOT='/opt/buildhome/.gimme/versions/go1.19.4.linux.amd64';
1:22:57 AM: export PATH="/opt/buildhome/.gimme/versions/go1.19.4.linux.amd64/bin:${PATH}";
1:22:57 AM: go version >&2;
1:22:57 AM: export GIMME_ENV="/opt/buildhome/.gimme/env/go1.19.4.linux.amd64.env"
1:22:57 AM: go version go1.19.4 linux/amd64
1:22:57 AM: Detected 2 framework(s)
1:22:57 AM: "next" at version "12.3.1"
1:22:57 AM: "create-react-app" at version "2.1.3"
1:22:57 AM: Installing missing commands
1:22:57 AM: Verify run directory
1:22:58 AM: ​
1:22:58 AM: ────────────────────────────────────────────────────────────────
1:22:58 AM:   Netlify Build                                                 
1:22:58 AM: ────────────────────────────────────────────────────────────────
1:22:58 AM: ​
1:22:58 AM: ❯ Version
1:22:58 AM:   @netlify/build 29.0.1
1:22:58 AM: ​
1:22:58 AM: ❯ Flags
1:22:58 AM:   baseRelDir: true
1:22:58 AM:   buildId: 639577118f8ab90008ec4eab
1:22:58 AM:   deployId: 639577118f8ab90008ec4ead
1:22:58 AM: ​
1:22:58 AM: ❯ Current directory
1:22:58 AM:   /opt/build/repo
1:22:58 AM: ​
1:22:58 AM: ❯ Config file
1:22:58 AM:   /opt/build/repo/netlify.toml
1:22:58 AM: ​
1:22:58 AM: ❯ Context
1:22:58 AM:   production
1:22:58 AM: ​
1:22:58 AM: ❯ Using Next.js Runtime - v4.29.2
1:23:00 AM: ​
1:23:00 AM: ────────────────────────────────────────────────────────────────
1:23:00 AM:   1. @netlify/plugin-nextjs (onPreBuild event)                  
1:23:00 AM: ────────────────────────────────────────────────────────────────
1:23:00 AM: ​
1:23:00 AM: No Next.js cache to restore.
1:23:00 AM: Netlify configuration property "build.environment.NEXT_PRIVATE_TARGET" value changed.
1:23:00 AM: ​
1:23:00 AM: (@netlify/plugin-nextjs onPreBuild completed in 16ms)
1:23:00 AM: ​
1:23:00 AM: ────────────────────────────────────────────────────────────────
1:23:00 AM:   2. build.command from netlify.toml                            
1:23:00 AM: ────────────────────────────────────────────────────────────────
1:23:00 AM: ​
1:23:00 AM: $ next build && next export
1:23:00 AM: warn  - No build cache found. Please configure build caching for faster rebuilds. Read more: https://nextjs.org/docs/messages/no-cache
1:23:00 AM: info  - Linting and checking validity of types...
1:23:01 AM: info  - Creating an optimized production build...
1:23:01 AM: info  - Disabled SWC as replacement for Babel because of custom Babel configuration ".babelrc" https://nextjs.org/docs/messages/swc-disabled
1:23:01 AM: info  - Using external babel configuration from /opt/build/repo/.babelrc
1:23:10 AM: info  - Compiled successfully
1:23:10 AM: info  - Collecting page data...
1:23:11 AM: (node:2175) [DEP0128] DeprecationWarning: Invalid 'main' field in '/opt/build/repo/node_modules/react-icons/package.json' of 'lib'. Please either fix that or report it to the module author
1:23:11 AM: (Use `node --trace-deprecation ...` to show where the warning was created)
1:23:11 AM: (node:2182) [DEP0128] DeprecationWarning: Invalid 'main' field in '/opt/build/repo/node_modules/react-icons/package.json' of 'lib'. Please either fix that or report it to the module author
1:23:11 AM: (Use `node --trace-deprecation ...` to show where the warning was created)
1:23:13 AM: info  - Generating static pages (0/9)
1:23:13 AM: info  - Generating static pages (2/9)
1:23:13 AM: (node:2203) [DEP0128] DeprecationWarning: Invalid 'main' field in '/opt/build/repo/node_modules/react-icons/package.json' of 'lib'. Please either fix that or report it to the module author
1:23:13 AM: (Use `node --trace-deprecation ...` to show where the warning was created)
1:23:13 AM: (node:2217) [DEP0128] DeprecationWarning: Invalid 'main' field in '/opt/build/repo/node_modules/react-icons/package.json' of 'lib'. Please either fix that or report it to the module author
1:23:13 AM: (Use `node --trace-deprecation ...` to show where the warning was created)
1:23:13 AM: []
1:23:13 AM: Error: Unable to resolve image URL from source (undefined)
1:23:13 AM:     at Object.urlForImage [as default] (/opt/build/repo/node_modules/@sanity/image-url/lib/node/urlForImage.js:47:15)
1:23:13 AM:     at ImageUrlBuilder.url (/opt/build/repo/node_modules/@sanity/image-url/lib/node/builder.js:193:37)
1:23:13 AM:     at ProjectsHero (/opt/build/repo/.next/server/chunks/485.js:287:140)
1:23:13 AM:     at Wc (/opt/build/repo/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:68:44)
1:23:13 AM:     at Zc (/opt/build/repo/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:70:253)
1:23:13 AM:     at Z (/opt/build/repo/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:89)
1:23:13 AM:     at $c (/opt/build/repo/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:78:98)
1:23:13 AM:     at bd (/opt/build/repo/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:77:404)
1:23:13 AM:     at Z (/opt/build/repo/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:217)
1:23:13 AM:     at $c (/opt/build/repo/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:78:98)
1:23:13 AM: Error occurred prerendering page "/projects". Read more: https://nextjs.org/docs/messages/prerender-error
1:23:13 AM: Error: Unable to resolve image URL from source (undefined)
1:23:13 AM:     at Object.urlForImage [as default] (/opt/build/repo/node_modules/@sanity/image-url/lib/node/urlForImage.js:47:15)
1:23:13 AM:     at ImageUrlBuilder.url (/opt/build/repo/node_modules/@sanity/image-url/lib/node/builder.js:193:37)
1:23:13 AM:     at ProjectsHero (/opt/build/repo/.next/server/chunks/485.js:287:140)
1:23:13 AM:     at Wc (/opt/build/repo/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:68:44)
1:23:13 AM:     at Zc (/opt/build/repo/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:70:253)
1:23:13 AM:     at Z (/opt/build/repo/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:89)
1:23:13 AM:     at $c (/opt/build/repo/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:78:98)
1:23:13 AM:     at bd (/opt/build/repo/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:77:404)
1:23:13 AM:     at Z (/opt/build/repo/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:217)
1:23:13 AM:     at $c (/opt/build/repo/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:78:98)
1:23:13 AM: info  - Generating static pages (4/9)
1:23:14 AM: info  - Generating static pages (6/9)
1:23:14 AM: {
1:23:14 AM:   _createdAt: '2022-12-08T00:19:33Z',
1:23:14 AM:   _id: 'df91dba4-997a-4282-a3e0-2a2793052a57',
1:23:14 AM:   _rev: 'cwf6PSmkIH3MXtFHz2b2Pt',
1:23:14 AM:   _type: 'projects',
1:23:14 AM:   _updatedAt: '2022-12-09T22:31:48Z',
1:23:14 AM:   category: 'Visual Design, UI/UX, Email Development',
1:23:14 AM:   description: 'A modern Email design created in Figma and implemented using HTML',
1:23:14 AM:   extra_info: 'The design theme for this project was to have a modern presentation for a fitness business. During the process, I chose colors from a given palette and used the best UI/UX practices to get a modern feel.',
1:23:14 AM:   id: '2',
1:23:14 AM:   imgUrl: {
1:23:14 AM:     _type: 'image',
1:23:14 AM:     asset: {
1:23:14 AM:       _ref: 'image-e02fafae9ce40c348895be53809c8f0ef12b553e-1080x3000-png',
1:23:14 AM:       _type: 'reference'
1:23:14 AM:     },
1:23:14 AM:     crop: {
1:23:14 AM:       _type: 'sanity.imageCrop',
1:23:14 AM:       bottom: 0.45795918367347044,
1:23:14 AM:       left: 0,
1:23:14 AM:       right: 0,
1:23:14 AM:       top: 0
1:23:14 AM:     },
1:23:14 AM:     hotspot: {
1:23:14 AM:       _type: 'sanity.imageHotspot',
1:23:14 AM:       height: 0.3314285714285713,
1:23:14 AM:       width: 1,
1:23:14 AM:       x: 0.5,
1:23:14 AM:       y: 0.16571428571428565
1:23:14 AM:     }
1:23:14 AM:   },
1:23:14 AM:   landing_paragraph_info: 'A simple HTML Email designed in figma and implemented using HTML.',
1:23:14 AM:   link: { _type: 'slug', current: 'vision-html-email' },
1:23:14 AM:   name: 'Vision HTML Email',
1:23:14 AM:   second_description: 'The design theme for this project was to have a modern presentation for a fitness business. During the process, I chose colors from a given palette and used the best UI/UX practices to get a modern feel.',
1:23:16 AM: Creating deploy upload records
1:23:14 AM:   second_heading: 'Getting Started',
1:23:14 AM:   story: 'The design theme for this project was to have a modern presentation for a fitness business. During the process, I chose colors from a given palette and used the best UI/UX practices to get a modern feel.',
1:23:14 AM:   tagline: 'Modern Design'
1:23:16 AM: Failed during stage 'building site': Build script returned non-zero exit code: 2 (https://ntl.fyi/exit-code-2)
1:23:14 AM: }
1:23:14 AM: {
1:23:14 AM:   _createdAt: '2022-12-07T14:14:23Z',
1:23:14 AM:   _id: 'dd89d254-c776-4119-9ddf-937cd0afce44',
1:23:14 AM:   _rev: 'VrdcoLtXxUWed6PHr9yXIV',
1:23:14 AM:   _type: 'projects',
1:23:14 AM:   _updatedAt: '2022-12-09T22:31:04Z',
1:23:14 AM:   category: 'Web-Development,Visual Design',
1:23:14 AM:   challenges: "My main challenge? the backend. I learned nodejs just to make this project and now I can say that I'm at the very least comfortable with it.",
1:23:14 AM:   description: 'A fullstack web application for delivering on-demand custom videos',
1:23:14 AM:   extra_info: 'Showman video is a full-stack web application that Uses a unique combination of technologies to deliver custom & on-demand videos to individuals and businesses.          It uses React for the front-end, Django for user authentication and page management, and the REST API to communicate with AWS for user renders',
1:23:14 AM:   id: '0',
1:23:14 AM:   imgUrl: {
1:23:14 AM:     _type: 'image',
1:23:14 AM:     asset: {
1:23:14 AM:       _ref: 'image-96e7c0bfa7c46bcf3cb7b4a51adfe6af7e0cec7e-1577x1756-png',
1:23:14 AM:       _type: 'reference'
1:23:14 AM:     }
1:23:14 AM:   },
1:23:14 AM:   landing_paragraph_info: 'My personal favorite project. A fullstack application to deliver videos to individuals and businesses. It uses custom technology from end to end.',
1:23:14 AM:   link: { _type: 'slug', current: 'showman-video' },
1:23:14 AM:   name: 'Showman Video',
1:23:14 AM:   second_description: 'I’ve been selling my graphics to people online since I was a kid, and it’s always something I’ve been passionate about.         Showman is the culmination of all of my ideas since starting my journey into graphics. It is the most challenging, and rewarding project that I’ve worked on. Each time I ran into a problem, I found a solution.               And I sure did run into a lot of problems. Python was my forte, but to fulfill my dream of creating this, I jumped completely into learning various web technologies from React to AWS. It took trial & error plus my signature night-hawkishness to get this project to where it is.              It uses Blender to render Motion Graphics generated by another project of mine: Rocketeer. It is something I’ve built from the ground up and am pretty proud of.',
1:23:14 AM:   second_heading: 'Getting Started',
1:23:14 AM:   story: 'I’ve been selling my graphics to people online since I was a kid, and it’s always something I’ve been passionate about.           Showman is the culmination of all of my ideas since starting my journey into graphics. It is the most challenging, and rewarding project that I’ve worked on. Each time I ran into a problem, I found a solution.                   And I sure did run into a lot of problems. Python was my forte, but to fulfill my dream of creating this, I jumped completely into learning various web technologies from React to AWS. It took trial & error plus my signature night-hawkishness to get this project to where it is.                  It uses Blender to render Motion Graphics generated by another project of mine: Rocketeer. It is something I’ve built from the ground up and am pretty proud of.',
1:23:14 AM:   tagline: 'The Magnum Opus',
1:23:14 AM:   tech_stack: 'HTML,CSS,JS,Figma,Blender,Python'
1:23:14 AM: }
1:23:14 AM: {
1:23:14 AM:   _createdAt: '2022-12-07T22:29:40Z',
1:23:14 AM:   _id: '12ad8a92-91d8-4a36-8d41-ce9f3f008ffe',
1:23:14 AM:   _rev: 'Bp455s9rtQ49wRO6vbjgkZ',
1:23:14 AM:   _type: 'projects',
1:23:14 AM:   _updatedAt: '2022-12-09T22:31:34Z',
1:23:14 AM:   category: 'Python Development, Visual Design',
1:23:14 AM:   challenges: "Creating the animation offset function proved to be the biggest challenge. The way Blender's system works, I have to access certain properties recursively -       so I had to have one function access multiple different values in a variety of ways in order to offset them by a constant integer value",
1:23:14 AM:   description: 'A Python video generation and workflow tool for Blender',
1:23:14 AM:   extra_info: 'Rocketeer is a tool that I created and use to generate Motion Graphics in Blender. It is a workflow tool that improves efficiency for the production of motion graphics in Blender. It is also capable of generating random styles based on an algorithm that derives processes from my workflow-style.',
1:23:14 AM:   id: '1',
1:23:14 AM:   imgUrl: {
1:23:14 AM:     _type: 'image',
1:23:14 AM:     asset: {
1:23:14 AM:       _ref: 'image-5261052e17153714fb5ee2ea001269bc642eed26-1920x1080-png',
1:23:14 AM:       _type: 'reference'
1:23:14 AM:     }
1:23:14 AM:   },
1:23:14 AM:   landing_paragraph_info: 'The man behind the curtain. The partner & wingman. Introducing Rocketeer',
1:23:14 AM:   link: { _type: 'slug', current: 'rocketeer' },
1:23:14 AM:   name: 'Rocketeer',
1:23:14 AM:   second_description: 'The problem: Blender has issues creating professional graphics on par with after effects(AE). Creating basic animations can take a long time, and making them look on par with after effects can take even longer.  Enter rocketeer. It makes generating presets and editing animations a breeze with Blender. Need a quick text animation? import it. Need an Instagram story? randomly geneerate it. It makes putting the building blocks of animation together an easy task. It combines muliple professional animation presets together and gets them ready for use on web servers.',
1:23:14 AM:   second_heading: 'Getting Started',
1:23:14 AM:   story: "Rocketer is a tool that I use to generate graphics in Blender. It is a workflow tool that improves efficiency for the production of motion graphics in Blender. It's also capable of generating random styles based on an algorithm that derives processes from my workflow-style.",
1:23:14 AM:   tagline: 'The Copilot'
1:23:14 AM: }
1:23:14 AM: info  - Generating static pages (9/9)
1:23:14 AM: > Build error occurred
1:23:14 AM: Error: Export encountered errors on following paths:
1:23:14 AM: 	/projects
1:23:14 AM:     at /opt/build/repo/node_modules/next/dist/export/index.js:404:19
1:23:14 AM:     at runMicrotasks (<anonymous>)
1:23:14 AM:     at processTicksAndRejections (node:internal/process/task_queues:96:5)
1:23:14 AM:     at async Span.traceAsyncFn (/opt/build/repo/node_modules/next/dist/trace/trace.js:79:20)
1:23:14 AM:     at async /opt/build/repo/node_modules/next/dist/build/index.js:1229:21
1:23:14 AM:     at async Span.traceAsyncFn (/opt/build/repo/node_modules/next/dist/trace/trace.js:79:20)
1:23:14 AM:     at async /opt/build/repo/node_modules/next/dist/build/index.js:1091:17
1:23:14 AM:     at async Span.traceAsyncFn (/opt/build/repo/node_modules/next/dist/trace/trace.js:79:20)
1:23:14 AM:     at async Object.build [as default] (/opt/build/repo/node_modules/next/dist/build/index.js:65:29)
1:23:14 AM: ​
1:23:14 AM: ────────────────────────────────────────────────────────────────
1:23:14 AM:   "build.command" failed                                        
1:23:14 AM: ────────────────────────────────────────────────────────────────
1:23:14 AM: ​
1:23:14 AM:   Error message
1:23:14 AM:   Command failed with exit code 1: next build && next export (https://ntl.fyi/exit-code-1)
1:23:14 AM: ​
1:23:14 AM:   Error location
1:23:14 AM:   In build.command from netlify.toml:
1:23:14 AM:   next build && next export
1:23:14 AM: ​
1:23:14 AM:   Resolved config
1:23:14 AM:   build:
1:23:14 AM:     command: next build && next export
1:23:14 AM:     commandOrigin: config
1:23:14 AM:     environment:
1:23:14 AM:       - NEXT_PUBLIC_DEPLOY_TOKEN
1:23:14 AM:       - NEXT_PUBLIC_SANITY_TOKEN
1:23:14 AM:       - NEXT_PRIVATE_TARGET
1:23:14 AM:     publish: /opt/build/repo/.next
1:23:14 AM:     publishOrigin: config
1:23:14 AM:   plugins:
1:23:14 AM:     - inputs: {}
1:23:14 AM:       origin: ui
1:23:14 AM:       package: '@netlify/plugin-nextjs'
1:23:14 AM: Caching artifacts
1:23:14 AM: Started saving node modules
1:23:14 AM: Finished saving node modules
1:23:14 AM: Started saving build plugins
1:23:14 AM: Finished saving build plugins
1:23:14 AM: Started saving pip cache
1:23:14 AM: Finished saving pip cache
1:23:14 AM: Started saving emacs cask dependencies
1:23:14 AM: Finished saving emacs cask dependencies
1:23:14 AM: Started saving maven dependencies
1:23:14 AM: Finished saving maven dependencies
1:23:14 AM: Started saving boot dependencies
1:23:14 AM: Finished saving boot dependencies
1:23:14 AM: Started saving rust rustup cache
1:23:14 AM: Finished saving rust rustup cache
1:23:14 AM: Started saving go dependencies
1:23:14 AM: Finished saving go dependencies
1:23:16 AM: Build failed due to a user error: Build script returned non-zero exit code: 2
1:23:16 AM: Failing build: Failed to build site
1:23:16 AM: Finished processing build request in 50.97594575s

I have lines in my code that log the project data that gets imported from sanity. My theory is that netlify is trying to generate the pages before getting the data from sanity, but I don’t know how to fix it.

Here is the repo link: GitHub - debdevs/debdevs-portfolio at sanity-test-branch

If anyone has any idea what the problem could be, I’d appreciate a tip in the right direction.

Hi @debdevs,

This is going into code-level debugging which is outside our scope of support. However, taking an initial look makes me wonder what’s going on here.

Based on this line:

it appears that you’re you’re fetching the data only after the useEffect triggers. So maybe when the posts are being fetched the first time, that useEffect doesn’t trigger, which is why the data is undefined?

Also, I’m not a daily React user, but last I recall useEffect is probably not using async/await by default, so even while your data is being fetched, the code is being parsed, which could also explain why the error happens before your data is being logged.

He’s using promises so no async/await issue there. I would expect this to work.

Promise is only being used to set the data, it’s not blocking the rest of the code from executing. It’s like:

let example = []
doSomething().then(() => {
  example = ['1']
})
console.log(example)
// will log out [] instead of ['1'] if doSomething() has not yet resolved

Instead, if it’s done like:

let example = []
doSomething().then(() => {
  example = ['1']
  console.log(example)
  // here example would always be ['1'] because it's running after the promise has resolved and the value has been updated
})

So, I can expect @debdevs’s case to fail.

Not sure if it counts as a solution, but I removed the projects page and that seemed to allow the project to deploy. Thanks to your input I realized the problem was in my code, so thank you!

Hi, @debdevs. Thank you for sharing how you resolved the issue.

1 Like