How to access detailed logs?

Trying to make a first deploy of new react app and getting error with path to log with more details.
How can I access this?

Hi, @jokuja. The build system VM is destroyed after the build is complete to that file isn’t recoverable. There are several ways to approach working around this.

Also, in most cases, you won’t need to use the detailed logs to debug the issue. If you do, it is likely easier to reproduce the issue locally and debug the issue that way. On the local system, you will be able to easily see those logs.

In other words, this file probably isn’t needed to debug some issue at Netlify. If you do need to use those logs to debug your site build, debugging locally first would likely be best.

However, if you do want to print those logs at Netlify, one method is to print that file to the console to have it logged on build failure only. Depending on how long the file is, you may need to use sleep to allow all the printed lines to be captured by the logger before the VM is shutdown.

For example, if your build command is this:

npm run build

Then you might log that file and delay exiting like so:

npm run build || { cat /opt/buildhome/.npm/_logs/* ; sleep 30 ; false; }

The “||” is the logical-OR. It means the code in the brackets will only be run if the original build command exits with an error code.

On other words, the addition above say “only on a build failure, run these commands (below)”:

cat /opt/buildhome/.npm/_logs/*
sleep 30
false

The cat line prints the logs. The sleep line delays the exit of the build image to allow the logs to be sent to the logging service. Note, this 30 second sleep might not be long enough if the log file is thousands of lines long. You may need to increase it depending on the file size. The false exits the build as an error.

Note, the “false;” at the end code in the brackets above is also quite important (and the ending semi-colon is required as well).

This command being run last means that the exit code will be non-zero. Non-zero exit codes are what determines if a build is a failing build or not. The “false;” fails the build.

We know this build failed or the code in the brackets would not have been run (because of the “||”. If the bracket code is run, the false; will mean the build will still exit as an error. We want the error because we do NOT want to publish a failing build. This is why “false;” is so important. It make certain the error stays an error. If the build is successful, the bracket code isn’t run so your successful builds won’t print that log or exit “false” - only failing builds will do this.

To summarize, you probably don’t want to print this file at Netlify at all. If you decide to do so anyway, the solution above (or some variation of it) will work.

If there are questions about any of this, please let us know.

Hi @luke,

Any update to show the detailed logs to debug the issue?

I change my package.json to

"scripts": {
    "prebuild": "rimraf dist",
    "build": "cross-env NODE_ENV=production vue-cli-service build ||  { cat /opt/buildhome/.npm/_logs/* ; sleep 30 ; false; } "
}

but it does not show the detailed log. Just Build failed due to a user error: Build script returned non-zero exit code: 2

Netlify suddenly cannot build my site (fully SPA with VueJs) 2 days ago and I cannot figure it out.
Currently for a quick fix, I’m have to prebuild in local machine, and push the /dist folder to GitHub repo, and disable build command on Netlify.

Thank you.

PS: I also try to set NETLIFY_BUILD_DEBUG=true, CI=false in build Environment, but nothing better.

Hi @lockevn,

Which site is this regarding? Could you share a deploy log link?

Thanks hrishikesh, this is the link to build failed log Netlify App

FYI, It was totally fine to build on Netlify few days ago. I guess something new happen on Netlify that I haven’t adapt.

11:49:17 PM: Build ready to start
11:49:20 PM: build-image version: fa439ad1ab9393b2c0d449d8d7c033927683f4b0
11:49:20 PM: build-image tag: v4.3.0
11:49:20 PM: buildbot version: bc6803b01c5912cd2cf1f2624903ebdf454d31b9
11:49:20 PM: Fetching cached dependencies
11:49:20 PM: Failed to fetch cache, continuing with build
11:49:20 PM: Starting to prepare the repo for build
11:49:21 PM: No cached dependencies found. Cloning fresh repo
11:49:21 PM: git clone https://github.com/XXX/XXX-web
11:49:22 PM: Preparing Git Reference refs/heads/main
11:49:22 PM: Parsing package.json dependencies
11:49:23 PM: 
​
❯ Initial build environment
baseRelDir: true
branch: main
context: production
cwd: /opt/build/repo
featureFlags: []
mode: buildbot
repositoryRoot: /opt/build/repo
siteId: ad24dc44-16ad-4480-9a4e-96ffef485899
​
❯ UI build settings
baseRelDir: true
build:
  command: npm run build
  environment:
    - CI
    - NETLIFY_BUILD_DEBUG
    - NODE_ENV
  publish: dist
​
❯ Resolved build environment
branch: main
buildDir: /opt/build/repo
configPath: /opt/build/repo/netlify.toml
context: production
env: []
​
❯ Resolved config
build:
  command: npm run build
  commandOrigin: ui
  environment:
    - CI
    - NETLIFY_BUILD_DEBUG
    - NODE_ENV
  publish: /opt/build/repo/dist
  publishOrigin: ui
redirects:
  - from: /*
    status: 200
    to: /index.html
redirectsOrigin: config

11:49:23 PM: Starting build script
11:49:23 PM: Installing dependencies
11:49:23 PM: Python version set to 2.7
11:49:24 PM: Downloading and installing node v12.18.0...
11:49:24 PM: Downloading https://nodejs.org/dist/v12.18.0/node-v12.18.0-linux-x64.tar.xz...
11:49:24 PM: Computing checksum with sha256sum
11:49:24 PM: Checksums matched!
11:49:26 PM: Now using node v12.18.0 (npm v6.14.4)
11:49:27 PM: Started restoring cached build plugins
11:49:27 PM: Finished restoring cached build plugins
11:49:27 PM: Attempting ruby version 2.7.2, read from environment
11:49:28 PM: Using ruby version 2.7.2
11:49:29 PM: Using PHP version 8.0
11:49:29 PM: Started restoring cached node modules
11:49:29 PM: Finished restoring cached node modules
11:49:29 PM: Installing NPM modules using NPM version 6.14.4
11:49:45 PM: > core-js@3.12.1 postinstall /opt/build/repo/node_modules/core-js
11:49:45 PM: > node -e "try{require('./postinstall')}catch(e){}"
11:49:45 PM: Thank you for using core-js ( https://github.com/zloirock/core-js ) for polyfilling JavaScript standard library!
11:49:45 PM: The project needs your help! Please consider supporting of core-js on Open Collective or Patreon: 
11:49:45 PM: > https://opencollective.com/core-js 
11:49:45 PM: > https://www.patreon.com/zloirock 
11:49:45 PM: Also, the author of core-js ( https://github.com/zloirock ) is looking for a good job -)
11:49:49 PM: added 24 packages from 22 contributors and audited 1658 packages in 19.587s
11:49:50 PM: 5 packages are looking for funding
11:49:50 PM:   run `npm fund` for details
11:49:50 PM: found 104 vulnerabilities (1 low, 102 moderate, 1 high)
11:49:50 PM:   run `npm audit fix` to fix them, or `npm audit` for details
11:49:50 PM: NPM modules installed
11:49:51 PM: Started restoring cached go cache
11:49:51 PM: Finished restoring cached go cache
11:49:51 PM: Installing Go version 1.14.4
11:49:55 PM: unset GOOS;
11:49:55 PM: unset GOARCH;
11:49:55 PM: export GOROOT='/opt/buildhome/.gimme_cache/versions/go1.14.4.linux.amd64';
11:49:55 PM: export PATH="/opt/buildhome/.gimme_cache/versions/go1.14.4.linux.amd64/bin:${PATH}";
11:49:55 PM: go version >&2;
11:49:55 PM: export GIMME_ENV="/opt/buildhome/.gimme_cache/env/go1.14.4.linux.amd64.env"
11:49:55 PM: go version go1.14.4 linux/amd64
11:49:55 PM: Installing missing commands
11:49:55 PM: Verify run directory
11:49:57 PM: ​
11:49:57 PM: ────────────────────────────────────────────────────────────────
11:49:57 PM:   Netlify Build                                                 
11:49:57 PM: ────────────────────────────────────────────────────────────────
11:49:57 PM: ​
11:49:57 PM: ❯ Version
11:49:57 PM:   @netlify/build 18.7.3
11:49:57 PM: ​
11:49:57 PM: ❯ Flags
11:49:57 PM:   apiHost: api.netlify.com
11:49:57 PM:   baseRelDir: true
11:49:57 PM:   branch: main
11:49:57 PM:   buildId: 6136468d64835500079d0da8
11:49:57 PM:   buildbotServerSocket: /tmp/netlify-buildbot-socket
11:49:57 PM:   cacheDir: /opt/build/cache
11:49:57 PM:   cachedConfigPath: /tmp/netlify_config.json
11:49:57 PM:   context: production
11:49:57 PM:   cwd: /opt/build/repo
11:49:57 PM:   deployId: 6136468d64835500079d0daa
11:49:57 PM:   featureFlags:
11:49:57 PM:     - zisiEsbuildDynamicImports
11:49:57 PM:   framework: vue
11:49:57 PM:   functionsDistDir: /tmp/zisi-6136468d64835500079d0daa
11:49:57 PM:   mode: buildbot
11:49:57 PM:   nodePath: /opt/buildhome/.nvm/versions/node/v12.18.0/bin/node
11:49:57 PM:   repositoryRoot: /opt/build/repo
11:49:57 PM:   saveConfig: true
11:49:57 PM:   sendStatus: true
11:49:57 PM:   siteId: ad24dc44-16ad-4480-9a4e-96ffef485899
11:49:57 PM:   statsd:
11:49:57 PM:     host: datadog-agent
11:49:57 PM:     port: 8125
11:49:57 PM:   testOpts:
11:49:57 PM:     silentLingeringProcesses: ''
11:49:57 PM: ​
11:49:57 PM: ❯ Current directory
11:49:57 PM:   /opt/build/repo
11:49:57 PM: ​
11:49:57 PM: ❯ Config file
11:49:57 PM:   /opt/build/repo/netlify.toml
11:49:57 PM: ​
11:49:57 PM: ❯ Resolved config
11:49:57 PM:   build:
11:49:57 PM:     command: npm run build
11:49:57 PM:     commandOrigin: ui
11:49:57 PM:     environment:
11:49:57 PM:       - CI
11:49:57 PM:       - NETLIFY_BUILD_DEBUG
11:49:57 PM:       - NODE_ENV
11:49:57 PM:     publish: /opt/build/repo/dist
11:49:57 PM:     publishOrigin: ui
11:49:57 PM:   redirects:
11:49:57 PM:     - from: /*
      status: 200
      to: /index.html
  redirectsOrigin: config
​
11:49:57 PM: ❯ Context
11:49:57 PM:   production
11:49:57 PM: ​
11:49:57 PM: ────────────────────────────────────────────────────────────────
11:49:57 PM:   1. Build command from Netlify app                             
11:49:57 PM: ────────────────────────────────────────────────────────────────
11:49:57 PM: ​
11:49:57 PM: $ npm run build
11:49:57 PM: > seidox-web@8.8.1 build /opt/build/repo
11:49:57 PM: > cross-env NODE_ENV=production vue-cli-service build
11:49:57 PM: sh: 1: cross-env: not found
11:49:57 PM: npm ERR! code ELIFECYCLE
11:49:57 PM: npm ERR! syscall spawn
11:49:57 PM: npm ERR! file sh
11:49:57 PM: npm ERR! errno ENOENT
11:49:57 PM: npm ERR! seidox-web@8.8.1 build: `cross-env NODE_ENV=production vue-cli-service build`
11:49:57 PM: npm ERR! spawn ENOENT
11:49:57 PM: npm ERR!
11:49:57 PM: npm ERR! Failed at the seidox-web@8.8.1 build script.
11:49:57 PM: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
11:49:57 PM: npm ERR! A complete log of this run can be found in:
11:49:57 PM: npm ERR!     /opt/buildhome/.npm/_logs/2021-09-06T16_49_57_401Z-debug.log
11:49:57 PM: ​
11:49:57 PM: ────────────────────────────────────────────────────────────────
11:49:57 PM:   "build.command" failed                                        
11:49:57 PM: ────────────────────────────────────────────────────────────────
11:49:57 PM: ​
11:49:57 PM:   Error message
11:49:57 PM:   Command failed with exit code 1: npm run build
11:49:57 PM: ​
11:49:57 PM:   Error location
11:49:57 PM:   In Build command from Netlify app:
11:49:57 PM:   npm run build
11:49:57 PM: ​
11:49:57 PM:   Resolved config
11:49:57 PM:   build:
11:49:57 PM:     command: npm run build
11:49:57 PM:     commandOrigin: ui
11:49:57 PM:     environment:
11:49:57 PM:       - CI
11:49:57 PM:       - NETLIFY_BUILD_DEBUG
11:49:57 PM:       - NODE_ENV
11:49:57 PM:     publish: /opt/build/repo/dist
11:49:57 PM:     publishOrigin: ui
11:49:57 PM:   redirects:
11:49:57 PM:     - from: /*
      status: 200
      to: /index.html
  redirectsOrigin: config
Caching artifacts
11:49:57 PM: Started saving node modules
11:49:57 PM: Finished saving node modules
11:49:57 PM: Started saving build plugins
11:49:57 PM: Finished saving build plugins
11:49:57 PM: Started saving pip cache
11:49:57 PM: Finished saving pip cache
11:49:57 PM: Started saving emacs cask dependencies
11:49:57 PM: Finished saving emacs cask dependencies
11:49:57 PM: Started saving maven dependencies
11:49:57 PM: Finished saving maven dependencies
11:49:57 PM: Started saving boot dependencies
11:49:57 PM: Finished saving boot dependencies
11:49:57 PM: Started saving rust rustup cache
11:49:57 PM: Finished saving rust rustup cache
11:49:58 PM: Started saving go dependencies
11:49:59 PM: Finished saving go dependencies
11:50:01 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
11:50:02 PM: Creating deploy upload records
11:50:02 PM: Failing build: Failed to build site
11:50:02 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2
11:50:02 PM: Finished processing build request in 41.688580862s

Just to rule out the obvious, do you have cross-env listed in the dependencies section of your package.json?

Yes, I have.

{
  "name": "XXX-web",
  "version": "8.8.1",
  "private": true,
  "scripts": {
    "prebuild": "rimraf dist",
    "dev": "cross-env NODE_ENV=dev npm run serve",
    "build": "cross-env NODE_ENV=production vue-cli-service build",
    "serve": "vue-cli-service serve",
    "test:unit": "vue-cli-service test:unit",
    "prettier": "npx prettier --fix ./src",
    "lint": "vue-cli-service lint --fix ./src"
  },
  "dependencies": {
    "axios": "^0.21.1",
    "core-js": "^3.6.5",
    "date-fns": "^2.22.1",
    "date-fns-tz": "^1.1.4",
    "deepmerge": "^4.2.2",
    "gachchan": "git+https://github.com/lockevn/gachchan.git#v4.1.1",
    "js-cookie": "^2.2.1",
    "lodash": "^4.17.21",
    "vue": "^2.6.11",
    "vue-class-component": "^7.2.6",
    "vue-property-decorator": "^9.1.2",
    "vue-router": "^3.2.0",
    "vuetify": "^2.4.0",
    "vuex": "^3.4.0",
    "vuex-map-fields": "^1.4.1",
    "vuex-persist": "^3.1.3"
  },
  "devDependencies": {
    "@vue/cli-plugin-babel": "~4.5.0",
    "@vue/cli-plugin-eslint": "~4.5.0",
    "@vue/cli-plugin-router": "~4.5.0",
    "@vue/cli-plugin-unit-jest": "~4.5.0",
    "@vue/cli-plugin-vuex": "~4.5.0",
    "@vue/cli-service": "~4.5.0",
    "@vue/eslint-config-prettier": "^6.0.0",
    "@vue/test-utils": "^1.0.3",
    "babel-eslint": "^10.1.0",
    "cross-env": "^7.0.3",
    "eslint": "^6.7.2",
    "eslint-plugin-prettier": "^3.3.1",
    "eslint-plugin-vue": "^6.2.2",
    "json-loader": "^0.5.7",
    "prettier": "^2.2.1",
    "raw-loader": "^4.0.2",
    "rimraf": "^3.0.2",
    "sass": "~1.32.12",
    "sass-loader": "^10.0.0",
    "stylus": "^0.54.7",
    "stylus-loader": "^3.0.2",
    "vue-cli-plugin-vuetify": "~2.4.0",
    "vue-template-compiler": "^2.6.11",
    "vuetify-loader": "^1.7.0",
    "webpack-bundle-analyzer": "^4.4.2"
  }
}

Yeah it’s in devDepencencies, could you move it to dependencies and try? While it’s not always the case, the packages within devDependencies might not be installed sometimes.

I tried (moved to dependencies, to just minute ago), but not success Netlify App

Your error is different this time. It now complains about rimraf not found. That’s yet another thing in your devDependencies. I think you should just move the entire thing out of that instead of doing it one by one.

1 Like

OK, I will do right now. We can assume that build on Netlify might have problem with devDependencies, can’t we?

It’s not a Netlify issue as such. Most CI processes will set the NODE_ENV to production and npm will skip devDependencies with that variable set.

But yes, the strange part is that, I’ve not seen this happen always.

Thank you hrishikesh! You are the best!
It works!

Still feel strange with my package.json right now :smiley: , but I will have to accept it. CI-related and build-dependencies is mandatory part of deploying/releasing.

To summarize for future readers

  • HOW: Move the entire thing in your package.json, from devDependencies to dependencies
  • WHY: most CI processes (include Netlify build) will set the NODE_ENV to production and npm will skip devDependencies with that variable set.
1 Like