Npm ERR! enoent ENOENT: no such file or directory, open ‘/opt/build/repo/package.json’

hi, i have same problem. I’ve tried many things but haven’t got any results yet, can you help me?

10:17:55 PM: Build ready to start
10:17:57 PM: build-image version: b0258b965567defc4a2d7e2f2dec2e00c8f73ad6
10:17:57 PM: build-image tag: v3.4.1
10:17:57 PM: buildbot version: 0e43e88a84db6c7a5f9e545ccf1a68b4e8b829b1
10:17:57 PM: Fetching cached dependencies
10:17:57 PM: Starting to download cache of 97.7MB
10:17:58 PM: Finished downloading cache in 1.708985025s
10:17:58 PM: Starting to extract cache
10:18:01 PM: Finished extracting cache in 2.984097404s
10:18:01 PM: Finished fetching cache in 4.743632462s
10:18:01 PM: Starting to prepare the repo for build
10:18:02 PM: Preparing Git Reference refs/heads/master
10:18:04 PM: Different build command detected, going to use the one specified in the Netlify configuration file: ‘CI= npm run build’ versus 'hugo --gc --minify -b URL' in the Netlify UI 10:18:04 PM: Starting build script 10:18:04 PM: Installing dependencies 10:18:04 PM: Python version set to 2.7 10:18:04 PM: Started restoring cached node version 10:18:07 PM: Finished restoring cached node version 10:18:08 PM: v12.18.0 is already installed. 10:18:09 PM: Now using node v12.18.0 (npm v6.14.4) 10:18:09 PM: Started restoring cached build plugins 10:18:09 PM: Finished restoring cached build plugins 10:18:09 PM: Attempting ruby version 2.7.1, read from environment 10:18:11 PM: Using ruby version 2.7.1 10:18:11 PM: Using PHP version 5.6 10:18:11 PM: 5.2 is already installed. 10:18:11 PM: Using Swift version 5.2 10:18:11 PM: Installing Hugo 0.75.1 10:18:11 PM: Hugo Static Site Generator v0.75.1-A4A7BAB7/extended linux/amd64 BuildDate: 2020-09-15T06:57:20Z 10:18:11 PM: Started restoring cached go cache 10:18:11 PM: Finished restoring cached go cache 10:18:11 PM: go version go1.14.4 linux/amd64 10:18:11 PM: go version go1.14.4 linux/amd64 10:18:11 PM: Installing missing commands 10:18:11 PM: Verify run directory 10:18:13 PM: ​ 10:18:13 PM: ┌─────────────────────────────┐ 10:18:13 PM: │ Netlify Build │ 10:18:13 PM: └─────────────────────────────┘ 10:18:13 PM: ​ 10:18:13 PM: ❯ Version 10:18:13 PM: @netlify/build 4.6.3 10:18:13 PM: ​ 10:18:13 PM: ❯ Flags 10:18:13 PM: deployId: 5f777ce390b28398a2a0ff09 10:18:13 PM: mode: buildbot 10:18:13 PM: ​ 10:18:13 PM: ❯ Current directory 10:18:13 PM: /opt/build/repo 10:18:13 PM: ​ 10:18:13 PM: ❯ Config file 10:18:13 PM: /opt/build/repo/netlify.toml 10:18:13 PM: ​ 10:18:13 PM: ❯ Context 10:18:13 PM: production 10:18:13 PM: ​ 10:18:13 PM: ┌────────────────────────────────────┐ 10:18:13 PM: │ 1. build.command from netlify.toml │ 10:18:13 PM: └────────────────────────────────────┘ 10:18:13 PM: ​ 10:18:13 PM: CI= npm run build
10:18:13 PM: npm ERR! code ENOENT
10:18:13 PM: npm ERR! syscall open
10:18:13 PM: npm ERR! path /opt/build/repo/package.json
10:18:13 PM: npm ERR! errno -2
10:18:13 PM: npm ERR! enoent ENOENT: no such file or directory, open ‘/opt/build/repo/package.json’
10:18:13 PM: npm ERR! enoent This is related to npm not being able to find a file.
10:18:13 PM: npm ERR! enoent
10:18:13 PM: npm ERR! A complete log of this run can be found in:
10:18:13 PM: npm ERR! /opt/buildhome/.npm/_logs/2020-10-02T19_18_13_525Z-debug.log
10:18:13 PM: ​
10:18:13 PM: ┌─────────────────────────────┐
10:18:13 PM: │ “build.command” failed │
10:18:13 PM: └─────────────────────────────┘
10:18:13 PM: ​
10:18:13 PM: Error message
10:18:13 PM: Command failed with exit code 254: CI= npm run build
10:18:13 PM: ​
10:18:13 PM: Error location
10:18:13 PM: In build.command from netlify.toml:
10:18:13 PM: CI= npm run build
10:18:13 PM: ​
10:18:13 PM: Resolved config
10:18:13 PM: build:
10:18:13 PM: command: CI= npm run build
10:18:13 PM: commandOrigin: config
10:18:13 PM: environment:
10:18:13 PM: - HUGO_VERSION
10:18:13 PM: - HUGO_ENABLEGITINFO
10:18:13 PM: - HUGO_ENV
10:18:13 PM: publish: /opt/build/repo/public
10:18:13 PM: headers:
10:18:13 PM: - for: ‘*.webmanifest’
10:18:13 PM: values:
10:18:13 PM: Content-Type: application/manifest+json; charset=UTF-8
10:18:13 PM: - for: index.xml
10:18:13 PM: values:
10:18:13 PM: Content-Type: application/rss+xml
10:18:13 PM: Caching artifacts
10:18:13 PM: Started saving build plugins
10:18:13 PM: Finished saving build plugins
10:18:13 PM: Started saving pip cache
10:18:13 PM: Finished saving pip cache
10:18:13 PM: Started saving emacs cask dependencies
10:18:13 PM: Finished saving emacs cask dependencies
10:18:13 PM: Started saving maven dependencies
10:18:13 PM: Finished saving maven dependencies
10:18:13 PM: Started saving boot dependencies
10:18:13 PM: Finished saving boot dependencies
10:18:13 PM: Started saving go dependencies
10:18:13 PM: Finished saving go dependencies
10:18:14 PM: Error running command: Build script returned non-zero exit code: 2
10:18:14 PM: Failing build: Failed to build site
10:18:14 PM: Failed during stage ‘building site’: Build script returned non-zero exit code: 2
10:18:14 PM: Finished processing build request in 17.032827372s

Hi, @konso. I moved this question to its own new topic as the error in these logs is unrelated the error in the original topic.

The error in this case is because there is no package.json file and you tried to use npm to run a script named “build”. This would require the script to be defined in that file:

10:18:13 PM: npm ERR! enoent ENOENT: no such file or directory, open ‘/opt/build/repo/package.json’

Because that file doesn’t exist the command “npm run build” gives this error.

I can see the change is in netlify.toml based on this line earlier in the logs:

10:18:04 PM: Different build command detected, going to use the one specified in the Netlify configuration file: ‘CI= npm run build’ versus 'hugo --gc --minify -b URL' in the Netlify UI 

It sounds like you might need to change the build command in netlify.toml to match what works in the web UI.

Do you have a working build for this site? If so, would you please send us a link to the deploy logs (or tell us the id for the deploy)?