Build Command failed - couldn't find package.json file?

Hey, new to development, and wanted to set up a simple HTML static site. Having a difficult time getting the site setup though. I believe I created a package.json file, but I’m not sure what the error that keeps failing my build is.

My site is: https://ryan-shumway-portfolio.netlify.app

The Full build log is below:
9:42:55 AM: Build ready to start
9:42:56 AM: build-image version: d2c6dbeac570350a387d832f64bc980dc964ad65 (focal)
9:42:56 AM: build-image tag: v4.8.0
9:42:56 AM: buildbot version: 29e546ddee264a16af472b38ccba15b350150213
9:42:56 AM: Fetching cached dependencies
9:42:57 AM: Starting to download cache of 13.4MB
9:42:57 AM: Finished downloading cache in 207.923876ms
9:42:57 AM: Starting to extract cache
9:42:57 AM: Finished extracting cache in 114.487299ms
9:42:57 AM: Finished fetching cache in 323.998366ms
9:42:57 AM: Starting to prepare the repo for build
9:42:57 AM: Preparing Git Reference refs/heads/main
9:42:58 AM: Parsing package.json dependencies
9:42:59 AM: Starting build script
9:42:59 AM: Installing dependencies
9:42:59 AM: Python version set to 2.7
9:42:59 AM: Downloading and installing node v16.15.0…
9:42:59 AM: Downloading https://nodejs.org/dist/v16.15.0/node-v16.15.0-linux-x64.tar.xz…
9:43:00 AM: Computing checksum with sha256sum
9:43:00 AM: Checksums matched!
9:43:02 AM: Now using node v16.15.0 (npm v8.5.5)
9:43:02 AM: Started restoring cached build plugins
9:43:02 AM: Finished restoring cached build plugins
9:43:02 AM: Attempting ruby version 2.7.2, read from environment
9:43:03 AM: Using ruby version 2.7.2
9:43:04 AM: Using PHP version 8.0
9:43:04 AM: Started restoring cached go cache
9:43:04 AM: Finished restoring cached go cache
9:43:04 AM: go version go1.16.5 linux/amd64
9:43:04 AM: go version go1.16.5 linux/amd64
9:43:04 AM: Installing missing commands
9:43:04 AM: Verify run directory
9:43:05 AM: ​
9:43:05 AM: ────────────────────────────────────────────────────────────────
9:43:05 AM: Netlify Build
9:43:05 AM: ────────────────────────────────────────────────────────────────
9:43:05 AM: ​
9:43:05 AM: ❯ Version
9:43:05 AM: @netlify/build 27.1.1
9:43:05 AM: ​
9:43:05 AM: ❯ Flags
9:43:05 AM: baseRelDir: true
9:43:05 AM: buildId: 6277e4ff6e3d85000847e370
9:43:05 AM: deployId: 6277e4ff6e3d85000847e372
9:43:05 AM: ​
9:43:05 AM: ❯ Current directory
9:43:05 AM: /opt/build/repo
9:43:05 AM: ​
9:43:05 AM: ❯ Config file
9:43:05 AM: No config file was defined: using default values.
9:43:05 AM: ​
9:43:05 AM: ❯ Context
9:43:05 AM: production
9:43:05 AM: ​
9:43:05 AM: ────────────────────────────────────────────────────────────────
9:43:05 AM: 1. Build command from Netlify app
9:43:05 AM: ────────────────────────────────────────────────────────────────
9:43:05 AM: ​
9:43:05 AM: $ yarn run build
9:43:05 AM: yarn run v1.22.10
9:43:05 AM: error Couldn’t find a package.json file in β€œ/opt/build/repo”
info Visit yarn run | Yarn for documentation about this command.
9:43:05 AM: ​
9:43:05 AM: ────────────────────────────────────────────────────────────────
9:43:05 AM: β€œbuild.command” failed
9:43:05 AM: ────────────────────────────────────────────────────────────────
9:43:05 AM: ​
9:43:05 AM: Error message
9:43:05 AM: Command failed with exit code 1: yarn run build (Search results for '"non-zero exit code: 1"' - Netlify Support Forums)
9:43:05 AM: ​
9:43:05 AM: Error location
9:43:05 AM: In Build command from Netlify app:
9:43:05 AM: yarn run build
9:43:05 AM: ​
9:43:05 AM: Resolved config
9:43:05 AM: build:
9:43:05 AM: command: yarn run build
9:43:05 AM: commandOrigin: ui
9:43:05 AM: publish: /opt/build/repo/ark
9:43:05 AM: publishOrigin: ui
9:43:06 AM: Caching artifacts
9:43:06 AM: Started saving build plugins
9:43:06 AM: Finished saving build plugins
9:43:06 AM: Started saving pip cache
9:43:06 AM: Finished saving pip cache
9:43:06 AM: Started saving emacs cask dependencies
9:43:06 AM: Finished saving emacs cask dependencies
9:43:06 AM: Started saving maven dependencies
9:43:06 AM: Finished saving maven dependencies
9:43:06 AM: Started saving boot dependencies
9:43:06 AM: Finished saving boot dependencies
9:43:06 AM: Started saving rust rustup cache
9:43:07 AM: Creating deploy upload records
9:43:06 AM: Finished saving rust rustup cache
9:43:06 AM: Started saving go dependencies
9:43:06 AM: Finished saving go dependencies
9:43:07 AM: Build failed due to a user error: Build script returned non-zero exit code: 2
9:43:07 AM: Failing build: Failed to build site
9:43:07 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)
9:43:08 AM: Finished processing build request in 11.156463619s


I have a package.json file, I attempted to connect a custom domain, but after that wasn’t working, I thought it might be easier to just use the default provided domain first, and that’s not working. Any feedback on how to set up the site would be great. Thanks!

Hey @ryanshumway,

Could you share your repo?

Since your screenshot has categorized all the files, we can’t understand your folder structure.

Here’s the link to my repo from GitHub. It’s technically private, not sure if that will affect your ability to view it.

https://github.com/ryanshumway/portfolio

Hey @ryanshumway

Correct, as it is a private repository, the public at large cannot see it.

Is it in the root of the repository? Or is it in a sub-directory?

Alright, @coelmay I changed the repository to public (GitHub - ryanshumway/portfolio: Personal Website)

The package.json file is in main folder (that’s the root folder correct? Still learning all the development vocabulary…).

I think I found the issue. Inside the package.json file, on the scripts line, my test is empty and says β€œError: no test specified\ && exit 1”. I’m betting that’s the problem.

What do I put in the Scripts: test:... portion of my package.json file?

hi ryan, the package.json is in this sub-folder of your repo:

https://github.com/ryanshumway/portfolio/blob/main/portfolio-website/package.json

i am thinking you don’t actually need a build command, as looking at your repo, it looks like you have some static html files in here:

especially as there is no actual build command in your package.json.

I think you are overcomplicating things a bit, and would just leave the build command blank in the netlify UI, set the base URL to portfolio/portfolio-website at main Β· ryanshumway/portfolio Β· GitHub and leave the publish URL blank, as you don’t need to have our robots actually build anything.

these concepts can be tricky to wrap your head around as a beginne, so do let us know if things aren’t clear still and we can explain in a different way.

1 Like

@Perry, Okay, so my package.json file isn’t in my root folder. That would be part of the problem?

Yes I’m just trying to put up a basic static site to test it and get it going, so I don’t need a build command then? So I should just delete the build command on the Netlify Ui since I’m not computing anything. I’ll give that a try and then respond here if it doesn’t work.

Thanks!

Yes. Because you a) have a build command; and b) have not set the base directory.

If you have no scripts that need building (I do see a tooltipper.ts file in the repository) there is no need for a build command. If you need a build command (e.g. yarn run build) the package.json need a build script. The package.json in your repository only has a test script.

If you do not need to build anything, the easiest way to get your portfolio deployed is to set the publish directory to portfolio-website and leave the base directory and build command empty.