Next version "unknown" and error: "next not found" when deploy

Go to site

I’ve had a bad time trying to register in npm when deploy, after that and a lot of proofs with different node versions, it seem is working with some setted environments. So i guess maybe is a problem with node versions and package installed,

The deploy in local is working fine.


NETLIFY DEPLOY

11:09:28 AM: build-image version: 5b0ab77c5e46895703390c45e86a907d4b78547b (focal)
11:09:28 AM: buildbot version: 5b0ab77c5e46895703390c45e86a907d4b78547b
11:09:28 AM: Fetching cached dependencies
11:09:28 AM: Failed to fetch cache, continuing with build
11:09:28 AM: Starting to prepare the repo for build
11:09:28 AM: No cached dependencies found. Cloning fresh repo
11:09:28 AM: git clone --filter=blob:none GitHub - leoncan122/survey-builder
11:09:29 AM: Preparing Git Reference refs/heads/main
11:09:29 AM: Parsing package.json dependencies
11:09:30 AM: Starting build script
11:09:30 AM: Installing dependencies
11:09:30 AM: Python version set to 2.7
11:09:31 AM: Downloading and installing node v16.19.1…
11:09:31 AM: Downloading https://nodejs.org/dist/v16.19.1/node-v16.19.1-linux-x64.tar.xz
11:09:31 AM: Computing checksum with sha256sum
11:09:31 AM: Checksums matched!
11:09:33 AM: Now using node v16.19.1 (npm v8.19.3)
11:09:33 AM: Enabling Node.js Corepack
11:09:33 AM: Started restoring cached build plugins
11:09:33 AM: Finished restoring cached build plugins
11:09:33 AM: Attempting Ruby version 2.7.2, read from environment
11:09:34 AM: Using Ruby version 2.7.2
11:09:34 AM: Using PHP version 8.0
11:09:34 AM: Started restoring cached corepack dependencies
11:09:34 AM: Finished restoring cached corepack dependencies
11:09:34 AM: No npm workspaces detected
11:09:34 AM: Started restoring cached node modules
11:09:34 AM: Finished restoring cached node modules
11:09:34 AM: Installing npm packages using npm version 8.19.3
11:09:34 AM: added 36 packages in 126ms
11:09:34 AM: npm packages installed
11:09:35 AM: Started restoring cached go cache
11:09:35 AM: Finished restoring cached go cache
11:09:35 AM: go version go1.19.6 linux/amd64
11:09:35 AM: Detected 1 framework(s)
11:09:35 AM: “next” at version “unknown”
11:09:35 AM: Installing missing commands
11:09:35 AM: Verify run directory
11:09:35 AM: Section completed: initializing
11:09:36 AM: ​
11:09:36 AM: Netlify Build
11:09:36 AM: ────────────────────────────────────────────────────────────────
11:09:36 AM: ​
11:09:36 AM: ❯ Version
11:09:36 AM: @netlify/build 29.5.7
11:09:36 AM: ​
11:09:36 AM: ❯ Flags
11:09:36 AM: baseRelDir: true
11:09:36 AM: buildId: 63ef524130e1320008ebb24f
11:09:36 AM: deployId: 63ef524130e1320008ebb251
11:09:36 AM: ​
11:09:36 AM: ❯ Current directory
11:09:36 AM: /opt/build/repo
11:09:36 AM: ​
11:09:36 AM: ❯ Config file
11:09:36 AM: No config file was defined: using default values.
11:09:36 AM: ​
11:09:36 AM: ❯ Context
11:09:36 AM: production
11:09:37 AM: ​
11:09:37 AM: ❯ Installing plugins
11:09:37 AM: - @netlify/plugin-nextjs@4.30.4
11:09:43 AM: ​
11:09:43 AM: ❯ Using Next.js Runtime - v4.30.4
11:09:44 AM: ​
11:09:44 AM: 1. @netlify/plugin-nextjs (onPreBuild event)
11:09:44 AM: ────────────────────────────────────────────────────────────────
11:09:44 AM: ​
11:09:44 AM: No Next.js cache to restore.
11:09:44 AM: Netlify configuration property “build.environment.NEXT_PRIVATE_TARGET” value changed.
11:09:44 AM: ​
11:09:44 AM: (@netlify/plugin-nextjs onPreBuild completed in 14ms)
11:09:44 AM: ​
11:09:44 AM: 2. Build command from Netlify app
11:09:44 AM: ────────────────────────────────────────────────────────────────
11:09:44 AM: ​
11:09:44 AM: $ npm run build
11:09:44 AM: > survey-builder@0.1.0 build
11:09:44 AM: > next build
11:09:44 AM: sh: 1: next: not found
11:09:44 AM: ​
11:09:44 AM: “build.command” failed
11:09:44 AM: ────────────────────────────────────────────────────────────────
11:09:44 AM: ​
11:09:44 AM: Error message
11:09:44 AM: Command failed with exit code 127: npm run build (Search results for '"non-zero exit code: 127"' - Netlify Support Forums)
11:09:44 AM: ​
11:09:44 AM: Error location
11:09:44 AM: In Build command from Netlify app:
11:09:44 AM: npm run build
11:09:44 AM: ​
11:09:44 AM: Resolved config
11:09:44 AM: build:
11:09:44 AM: command: npm run build
11:09:44 AM: commandOrigin: ui
11:09:44 AM: environment:
11:09:44 AM: - NETLIFY_GRAPH_TOKEN
11:09:44 AM: - NEXT_PUBLIC_SERVER_URL
11:09:44 AM: - NPM_FLAGS
11:09:44 AM: - NPM_TOKEN
11:09:44 AM: - ONEGRAPH_AUTHLIFY_TOKEN
11:09:44 AM: - NEXT_PRIVATE_TARGET
11:09:44 AM: publish: /opt/build/repo/.next
11:09:44 AM: publishOrigin: ui
11:09:44 AM: functionsDirectory: /opt/build/repo/.netlify/functions
11:09:46 AM: Failed during stage ‘building site’: Build script returned non-zero exit code: 2 (Search results for '"non-zero exit code: 2"' - Netlify Support Forums)
11:09:44 AM: plugins:
11:09:44 AM: - inputs: {}
11:09:44 AM: origin: ui
11:09:44 AM: package: ‘@netlify/plugin-nextjs’
11:09:45 AM: Caching artifacts
11:09:45 AM: Started saving node modules
11:09:45 AM: Finished saving node modules
11:09:45 AM: Started saving build plugins
11:09:45 AM: Finished saving build plugins
11:09:45 AM: Started saving corepack cache
11:09:45 AM: Finished saving corepack cache
11:09:45 AM: Started saving pip cache
11:09:45 AM: Finished saving pip cache
11:09:45 AM: Started saving emacs cask dependencies
11:09:45 AM: Finished saving emacs cask dependencies
11:09:45 AM: Started saving maven dependencies
11:09:45 AM: Finished saving maven dependencies
11:09:45 AM: Started saving boot dependencies
11:09:45 AM: Finished saving boot dependencies
11:09:45 AM: Started saving rust rustup cache
11:09:45 AM: Finished saving rust rustup cache
11:09:45 AM: Started saving go dependencies
11:09:45 AM: Finished saving go dependencies
11:09:45 AM: Build failed due to a user error: Build script returned non-zero exit code: 2
11:09:46 AM: Failing build: Failed to build site
11:09:46 AM: Finished processing build request in 17.549s


LOCAL DEPLOY

info - Loaded env from C:\Users\leonc\bh\survey-builder.env.local
info - Linting and checking validity of types
(node:21760) [DEP_WEBPACK_MODULE_UPDATE_HASH] DeprecationWarning: Module.updateHash: Use new ChunkGraph API
(Use node --trace-deprecation ... to show where the warning was created)
info - Creating an optimized production build
info - Compiled successfully
info - Collecting page data
[ ] info - Generating static pages (0/6)
info - Generating static pages (6/6)
info - Finalizing page optimization

Route (pages) Size First Load JS
┌ ○ / 573 B 75.9 kB
├ /_app 0 B 75.3 kB
├ λ /[id]/relatedSurvey 1.93 kB 292 kB
├ λ /[id]/survey 1.92 kB 292 kB
├ ○ /404 181 B 75.5 kB
├ λ /api/createQuestions 0 B 75.3 kB
├ λ /api/hello 0 B 75.3 kB
├ ○ /creator 1.83 kB 77.1 kB
├ ○ /creator/[id]/related-survey 1.88 kB 77.2 kB
├ λ /dashboard/[id] 3.3 kB 78.6 kB
├ λ /dashboard/[id]/relatedSurveyOutputResults 808 B 76.1 kB
├ λ /dashboard/[id]/surveyOutputResults 840 B 76.1 kB
├ λ /editor/[id] 1.92 kB 641 kB
├ λ /editor/[id]/related-survey 1.93 kB 641 kB
├ λ /mysurveys 797 B 76.1 kB
├ λ /reports 2.72 kB 78 kB
└ ○ /test 5.05 kB 80.3 kB

  • First Load JS shared by all 76.3 kB
    ├ chunks/framework-114634acb84f8baa.js 45.4 kB
    ├ chunks/main-66ca454f7bdf962f.js 27 kB
    ├ chunks/pages/_app-71f819d06f67f390.js 678 B
    ├ chunks/webpack-aa439a6ee30809e3.js 2.21 kB
    └ css/a0d12124071d62a7.css 1.04 kB

λ (Server) server-side renders at runtime (uses getInitialProps or getServerSideProps)
○ (Static) automatically rendered as static HTML (uses no initial props)

And this are my package.json

{
  "name": "survey-builder",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "lint": "next lint"
  },
  "dependencies": {
    "@leoncan122/react-form-lib": "0.3.8",
    "@next/font": "13.1.3",
    "bootstrap": "5.2.3",
    "next": "13.0.7",
    "react": "18.2.0",
    "react-dom": "18.2.0",
    "survey-creator-react": "1.9.65",
    "survey-react-ui": "^1.9.64"
  }
}

And the first package section of mi Package.lock.json, because i am presumming that is not correct, the dependencies object does not has a key…

"name": "survey-builder",
  "version": "0.1.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "survey-builder",
      "version": "0.1.0",
      "dependencies": {
        "@leoncan122/react-form-lib": "0.3.8",
        "@next/font": "13.1.3",
        "bootstrap": "5.2.3",
        "next": "13.0.7",
        "react": "18.2.0",
        "react-dom": "18.2.0",
        "survey-creator-react": "1.9.65",
        "survey-react-ui": "^1.9.64"
      }
    },

The issue can be solved using:

Thank you so much ! this solves the problem :smiley:

Hi :wave:t6: @leoncan122 thanks so much for confirming you resolved your issue.