Need help with building site from github

Hey everyone,
I’m kinda new to this, but I have a friend who built website with next.js and wanted to give it a try to see how it works. I got files for his site (with his premission ofc), and uploaded them to my repository on Github. I tried building then from Netlify, but keep getting error when building:

2:58:04 PM: Waiting for other deploys from your team to complete. Check the queue: Netlify App
2:59:00 PM: Build ready to start
2:59:07 PM: build-image version: d05976bd3309b73a86eaa327bf80e105ff13f5e4 (focal)
2:59:07 PM: build-image tag: v4.13.0
2:59:07 PM: buildbot version: 3a000de5d3727998f3297394596d287d7e49aecd
2:59:07 PM: Building without cache
2:59:07 PM: Starting to prepare the repo for build
2:59:07 PM: No cached dependencies found. Cloning fresh repo
2:59:07 PM: git clone GitHub - MihailoNP/Carbookingtest
2:59:07 PM: Preparing Git Reference refs/heads/main
2:59:07 PM: Parsing package.json dependencies
2:59:09 PM: Starting build script
2:59:09 PM: Installing dependencies
2:59:09 PM: Python version set to 2.7
2:59:09 PM: v16.18.0 is already installed.
2:59:09 PM: Now using node v16.18.0 (npm v8.19.2)
2:59:10 PM: Enabling node corepack
2:59:10 PM: Started restoring cached build plugins
2:59:10 PM: Finished restoring cached build plugins
2:59:10 PM: Attempting ruby version 2.7.2, read from environment
2:59:10 PM: Using ruby version 2.7.2
2:59:10 PM: Using PHP version 8.0
2:59:11 PM: No npm workspaces detected
2:59:11 PM: Started restoring cached node modules
2:59:11 PM: Finished restoring cached node modules
2:59:11 PM: Installing NPM modules using NPM version 8.19.2
2:59:12 PM: npm WARN old lockfile
2:59:12 PM: npm WARN old lockfile The package-lock.json file was created with an old version of npm,
2:59:12 PM: npm WARN old lockfile so supplemental metadata must be fetched from the registry.
2:59:12 PM: npm WARN old lockfile
2:59:12 PM: npm WARN old lockfile This is a one-time fix-up, please be patient…
2:59:12 PM: npm WARN old lockfile
2:59:16 PM: 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: Array.prototype.sort() - JavaScript | MDN
2:59:16 PM: npm WARN deprecated multer@1.4.4: Multer 1.x is affected by CVE-2022-24434. This is fixed in v1.4.4-lts.1 which drops support for versions of Node.js before 6. Please upgrade to at least Node.js 6 and version 1.4.4-lts.1 of Multer. If you need support for older versions of Node.js, we are open to accepting patches that would fix the CVE on the main 1.x release line, whilst maintaining compatibility with Node.js 0.10.
2:59:16 PM: npm WARN deprecated @types/bson@4.2.0: This is a stub types definition. bson provides its own type definitions, so you do not need this installed.
2:59:29 PM: added 520 packages, and audited 521 packages in 17s
2:59:29 PM: 78 packages are looking for funding
2:59:29 PM: run npm fund for details
2:59:29 PM: 5 vulnerabilities (1 moderate, 4 high)
2:59:29 PM: To address all issues (including breaking changes), run:
2:59:29 PM: npm audit fix --force
2:59:29 PM: Run npm audit for details.
2:59:29 PM: NPM modules installed
2:59:29 PM: Started restoring cached go cache
2:59:29 PM: Finished restoring cached go cache
2:59:29 PM: Installing Go version 1.17 (requested 1.17)
2:59:34 PM: unset GOOS;
2:59:34 PM: unset GOARCH;
2:59:34 PM: export GOROOT=‘/opt/buildhome/.gimme/versions/go1.17.linux.amd64’;
2:59:34 PM: export PATH=“/opt/buildhome/.gimme/versions/go1.17.linux.amd64/bin:${PATH}”;
2:59:34 PM: go version >&2;
2:59:34 PM: export GIMME_ENV=“/opt/buildhome/.gimme/env/go1.17.linux.amd64.env”
2:59:34 PM: go version go1.17 linux/amd64
2:59:34 PM: Installing missing commands
2:59:34 PM: Verify run directory
2:59:35 PM: ​
2:59:35 PM: ────────────────────────────────────────────────────────────────
2:59:35 PM: Netlify Build
2:59:35 PM: ────────────────────────────────────────────────────────────────
2:59:35 PM: ​
2:59:35 PM: ❯ Version
2:59:35 PM: @netlify/build 27.20.6
2:59:35 PM: ​
2:59:35 PM: ❯ Flags
2:59:35 PM: baseRelDir: true
2:59:35 PM: buildId: 634ff45c7c99960609c008bf
2:59:35 PM: deployId: 634ff45c7c99960609c008c1
2:59:35 PM: ​
2:59:35 PM: ❯ Current directory
2:59:35 PM: /opt/build/repo
2:59:35 PM: ​
2:59:35 PM: ❯ Config file
2:59:35 PM: /opt/build/repo/netlify.toml
2:59:35 PM: ​
2:59:35 PM: ❯ Context
2:59:35 PM: production
2:59:35 PM: ​
2:59:35 PM: ❯ Installing plugins
2:59:35 PM: - @netlify/plugin-nextjs@4.26.0
2:59:41 PM: ​
2:59:41 PM: ❯ Using Next.js Runtime - v4.26.0
2:59:42 PM: ​
2:59:42 PM: ────────────────────────────────────────────────────────────────
2:59:42 PM: 1. @netlify/plugin-nextjs (onPreBuild event)
2:59:42 PM: ────────────────────────────────────────────────────────────────
2:59:42 PM: ​
2:59:42 PM: No Next.js cache to restore.
2:59:42 PM: Netlify configuration property “build.environment.NEXT_PRIVATE_TARGET” value changed.
2:59:42 PM: ​
2:59:42 PM: (@netlify/plugin-nextjs onPreBuild completed in 16ms)
2:59:42 PM: ​
2:59:42 PM: ────────────────────────────────────────────────────────────────
2:59:42 PM: 2. Build command from Netlify app
2:59:42 PM: ────────────────────────────────────────────────────────────────
2:59:42 PM: ​
2:59:42 PM: $ npm run build
2:59:42 PM: > build
2:59:42 PM: > next build
2:59:43 PM: warn - No build cache found. Please configure build caching for faster rebuilds. Read more: no-cache | Next.js
2:59:43 PM: info - Linting and checking validity of types…
2:59:43 PM: warn - No ESLint configuration detected. Run next lint to begin setup
2:59:44 PM: info - Creating an optimized production build…
2:59:57 PM: info - Compiled successfully
2:59:57 PM: info - Collecting page data…
2:59:58 PM: > Build error occurred
2:59:58 PM: Error: Please define the MONGODB_URI environment variable inside .env.local
2:59:58 PM: at Object.110 (/opt/build/repo/.next/server/chunks/82.js:344:11)
2:59:58 PM: at webpack_require (/opt/build/repo/.next/server/webpack-runtime.js:25:42)
2:59:58 PM: at Object.4625 (/opt/build/repo/.next/server/pages/cars.js:23:69)
2:59:58 PM: at webpack_require (/opt/build/repo/.next/server/webpack-runtime.js:25:42)
2:59:58 PM: at webpack_exec (/opt/build/repo/.next/server/pages/cars.js:166:39)
2:59:58 PM: at /opt/build/repo/.next/server/pages/cars.js:167:85
2:59:58 PM: at Function.webpack_require.X (/opt/build/repo/.next/server/webpack-runtime.js:108:21)
2:59:58 PM: at /opt/build/repo/.next/server/pages/cars.js:167:47
2:59:58 PM: at Object. (/opt/build/repo/.next/server/pages/cars.js:170:3)
2:59:58 PM: at Module._compile (node:internal/modules/cjs/loader:1155:14) {
2:59:58 PM: type: ‘Error’
2:59:58 PM: }
2:59:58 PM: ​
2:59:58 PM: ────────────────────────────────────────────────────────────────
2:59:58 PM: “build.command” failed
2:59:58 PM: ────────────────────────────────────────────────────────────────
2:59:58 PM: ​
2:59:58 PM: Error message
2:59:58 PM: Command failed with exit code 1: npm run build (Search results for '"non-zero exit code: 1"' - Netlify Support Forums)
2:59:58 PM: ​
2:59:58 PM: Error location
2:59:58 PM: In Build command from Netlify app:
2:59:58 PM: npm run build
2:59:58 PM: ​
2:59:58 PM: Resolved config
2:59:58 PM: build:
2:59:58 PM: command: npm run build
2:59:58 PM: commandOrigin: ui
2:59:58 PM: environment:
2:59:58 PM: - NEXT_PRIVATE_TARGET
2:59:58 PM: publish: /opt/build/repo/.next
2:59:58 PM: publishOrigin: ui
2:59:58 PM: plugins:
2:59:58 PM: - inputs: {}
2:59:58 PM: origin: ui
2:59:58 PM: package: ‘@netlify/plugin-nextjs’
2:59:59 PM: Caching artifacts
2:59:59 PM: Started saving node modules
2:59:59 PM: Finished saving node modules
2:59:59 PM: Started saving build plugins
2:59:59 PM: Finished saving build plugins
2:59:59 PM: Started saving pip cache
2:59:59 PM: Finished saving pip cache
2:59:59 PM: Started saving emacs cask dependencies
2:59:59 PM: Finished saving emacs cask dependencies
2:59:59 PM: Started saving maven dependencies
2:59:59 PM: Finished saving maven dependencies
2:59:59 PM: Started saving boot dependencies
2:59:59 PM: Finished saving boot dependencies
2:59:59 PM: Started saving rust rustup cache
2:59:59 PM: Finished saving rust rustup cache
2:59:59 PM: Started saving go dependencies
2:59:59 PM: Finished saving go dependencies
3:00:00 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
3:00:00 PM: Creating deploy upload records
3:00:00 PM: Failing build: Failed to build site
3:00:00 PM: Failed during stage ‘building site’: Build script returned non-zero exit code: 2 (Search results for '"non-zero exit code: 2"' - Netlify Support Forums)
3:00:00 PM: Finished processing build request in 53.156387266s

Hi @Kilgharah, welcome and thanks for posting.

As you can see from the quoted error above, you have not set the environment variable MONGODB_URI used in your project.
Make sure you set all environment variables used in your project.

Kindly check the link below on how to set environment variables in Next.js projects deployed to Netlify.

Let me know the outcome after the suggestions.
Thanks.