First deploy problems. React / Node.js / Webpack build failing

Hi!

I’d love to get going with Netlify, but I am not having a flowing first experience with real world project.

Its a React, Node, npm, Webpack stack.

https://heuristic-poitras-dfa923.netlify.app/

Locally running fine, in DEVELOPMENT and PRODUCTION envs.

I have set Netlify environment variables correctly AFAIK

Here is requested full log.

11:01:57 AM: Build ready to start
11:02:00 AM: build-image version: 73def8bb10593b9b818f44989a75ea508018ccb7 (focal)
11:02:00 AM: build-image tag: v4.5.2
11:02:00 AM: buildbot version: 007e3cee9690c5dd1ea3d0f59b0390ab3a4afae2
11:02:00 AM: Fetching cached dependencies
11:02:00 AM: Failed to fetch cache, continuing with build
11:02:00 AM: Starting to prepare the repo for build
11:02:00 AM: No cached dependencies found. Cloning fresh repo
11:02:00 AM: git clone https://github.com/sonifydata/twotone
11:02:07 AM: Preparing Git Reference pull/3/head
11:02:10 AM: Parsing package.json dependencies
11:02:10 AM: ​❯ Initial build environmentbaseRelDir: truebranch: v2.1-devcontext: deploy-previewcwd: /opt/build/repofeatureFlags: []mode: buildbotrepositoryRoot: /opt/build/repositeId: 440ce41c-67ef-42b8-ad64-bd12017f8369​❯ UI build settingsbaseRelDir: truebuild:  command: npm run build  environment:    - NETLIFY_BUILD_DEBUG    - NODE_ENV    - NODE_VERSION    - REVIEW_ID  publish: dist/​❯ Resolved build environmentbranch: v2.1-devbuildDir: /opt/build/repocontext: deploy-previewenv: []​❯ Resolved configbuild:  command: npm run build  commandOrigin: ui  environment:    - NETLIFY_BUILD_DEBUG    - NODE_ENV    - NODE_VERSION    - REVIEW_ID  publish: /opt/build/repo/dist  publishOrigin: ui
11:02:11 AM: Starting build script
11:02:11 AM: Installing dependencies
11:02:11 AM: Python version set to 2.7
11:02:11 AM: Attempting node version '13' from .nvmrc
11:02:12 AM: Downloading and installing node v13.14.0...
11:02:12 AM: Downloading https://nodejs.org/dist/v13.14.0/node-v13.14.0-linux-x64.tar.xz...
11:02:12 AM: Computing checksum with sha256sum
11:02:12 AM: Checksums matched!
11:02:16 AM: Now using node v13.14.0 (npm v6.14.4)
11:02:16 AM: Started restoring cached build plugins
11:02:16 AM: Finished restoring cached build plugins
11:02:16 AM: Attempting ruby version 2.7.2, read from environment
11:02:17 AM: Using ruby version 2.7.2
11:02:18 AM: Using PHP version 8.0
11:02:18 AM: Started restoring cached node modules
11:02:18 AM: Finished restoring cached node modules
11:02:18 AM: Installing NPM modules using NPM version 6.14.4
11:02:41 AM: > leveldown@5.6.0 install /opt/build/repo/node_modules/leveldown
11:02:41 AM: > node-gyp-build
11:02:41 AM: > jss@9.8.7 postinstall /opt/build/repo/node_modules/jss
11:02:41 AM: > node -e "console.log('\u001b[35m\u001b[1mLove JSS? You can now support us on open collective:\u001b[22m\u001b[39m\n > \u001b[34mhttps://opencollective.com/jss/donate\u001b[0m')"
11:02:42 AM: Love JSS? You can now support us on open collective:
11:02:42 AM:  > https://opencollective.com/jss/donate
11:02:45 AM: npm WARN twotone@0.0.2 No repository field.
11:02:45 AM: npm WARN The package xlsx is included as both a dev and production dependency.
11:02:45 AM: added 349 packages from 439 contributors and audited 2388 packages in 25.839s
11:02:46 AM: 15 packages are looking for funding
11:02:46 AM:   run `npm fund` for details
11:02:46 AM: found 38 vulnerabilities (4 low, 25 moderate, 9 high)
11:02:46 AM:   run `npm audit fix` to fix them, or `npm audit` for details
11:02:47 AM: NPM modules installed
11:02:47 AM: Started restoring cached go cache
11:02:47 AM: Finished restoring cached go cache
11:02:47 AM: go version go1.16.5 linux/amd64
11:02:47 AM: go version go1.16.5 linux/amd64
11:02:47 AM: Installing missing commands
11:02:47 AM: Verify run directory
11:02:49 AM: ​
11:02:49 AM: ────────────────────────────────────────────────────────────────
11:02:49 AM:   Netlify Build                                                 
11:02:49 AM: ────────────────────────────────────────────────────────────────
11:02:49 AM: ​
11:02:49 AM: ❯ Version
11:02:49 AM:   @netlify/build 26.1.3
11:02:49 AM: ​
11:02:49 AM: ❯ Flags
11:02:49 AM:   apiHost: api.netlify.com
11:02:49 AM:   baseRelDir: true
11:02:49 AM:   branch: v2.1-dev
11:02:49 AM:   buildId: 61e53e95de13ec0007611f4a
11:02:49 AM:   buildbotServerSocket: /tmp/netlify-buildbot-socket
11:02:49 AM:   cacheDir: /opt/build/cache
11:02:49 AM:   cachedConfigPath: /tmp/netlify_config.json
11:02:49 AM:   context: deploy-preview
11:02:49 AM:   cwd: /opt/build/repo
11:02:49 AM:   deployId: 61e53e95de13ec0007611f4c
11:02:49 AM:   featureFlags:
11:02:49 AM:     - buildbot_build_go_functions
11:02:49 AM:     - buildbot_create_functions_manifest
11:02:49 AM:     - zisi_parse_isc
11:02:49 AM:   framework: unknown
11:02:49 AM:   functionsDistDir: /tmp/zisi-61e53e95de13ec0007611f4c
11:02:49 AM:   mode: buildbot
11:02:49 AM:   nodePath: /opt/buildhome/.nvm/versions/node/v13.14.0/bin/node
11:02:49 AM:   repositoryRoot: /opt/build/repo
11:02:49 AM:   saveConfig: true
11:02:49 AM:   sendStatus: true
11:02:49 AM:   siteId: 440ce41c-67ef-42b8-ad64-bd12017f8369
11:02:49 AM:   statsd:
11:02:49 AM:     host: datadog-agent
11:02:49 AM:     port: 8125
11:02:49 AM:   testOpts:
11:02:49 AM:     silentLingeringProcesses: ''
11:02:49 AM: ​
11:02:49 AM: ❯ Current directory
11:02:49 AM:   /opt/build/repo
11:02:49 AM: ​
11:02:49 AM: ❯ Config file
11:02:49 AM:   No config file was defined: using default values.
11:02:49 AM: ​
11:02:49 AM: ❯ Resolved config
11:02:49 AM:   build:
11:02:49 AM:     command: npm run build
11:02:49 AM:     commandOrigin: ui
11:02:49 AM:     environment:
11:02:49 AM:       - NETLIFY_BUILD_DEBUG
11:02:49 AM:       - NODE_ENV
11:02:49 AM:       - NODE_VERSION
11:02:49 AM:       - REVIEW_ID
11:02:49 AM:     publish: /opt/build/repo/dist
11:02:49 AM:     publishOrigin: ui
11:02:49 AM: ​
11:02:49 AM: ❯ Context
11:02:49 AM:   deploy-preview
11:02:49 AM: ​
11:02:49 AM: ────────────────────────────────────────────────────────────────
11:02:49 AM:   1. Build command from Netlify app                             
11:02:49 AM: ────────────────────────────────────────────────────────────────
11:02:49 AM: ​
11:02:49 AM: $ npm run build
11:02:50 AM: > twotone@0.0.2 build /opt/build/repo
11:02:50 AM: > NODE_ENV=production webpack
11:02:50 AM: sh: 1: webpack: not found
11:02:50 AM: npm ERR! code ELIFECYCLE
11:02:50 AM: npm ERR! syscall spawn
11:02:50 AM: npm ERR! file sh
11:02:50 AM: npm ERR! errno ENOENT
11:02:50 AM: npm ERR! twotone@0.0.2 build: `NODE_ENV=production webpack`
11:02:50 AM: npm ERR! spawn ENOENT
11:02:50 AM: npm ERR!
11:02:50 AM: npm ERR! Failed at the twotone@0.0.2 build script.
11:02:50 AM: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
11:02:50 AM: npm ERR! A complete log of this run can be found in:
11:02:50 AM: npm ERR!     /opt/buildhome/.npm/_logs/2022-01-17T10_02_50_212Z-debug.log
11:02:50 AM: ​
11:02:50 AM: ────────────────────────────────────────────────────────────────
11:02:50 AM:   "build.command" failed                                        
11:02:50 AM: ────────────────────────────────────────────────────────────────
11:02:50 AM: ​
11:02:50 AM:   Error message
11:02:50 AM:   Command failed with exit code 1: npm run build
11:02:50 AM: ​
11:02:50 AM:   Error location
11:02:50 AM:   In Build command from Netlify app:
11:02:50 AM:   npm run build
11:02:50 AM: ​
11:02:50 AM:   Resolved config
11:02:50 AM:   build:
11:02:50 AM:     command: npm run build
11:02:50 AM:     commandOrigin: ui
11:02:50 AM:     environment:
11:02:50 AM:       - NETLIFY_BUILD_DEBUG
11:02:50 AM:       - NODE_ENV
11:02:50 AM:       - NODE_VERSION
11:02:50 AM:       - REVIEW_ID
11:02:50 AM:     publish: /opt/build/repo/dist
11:02:50 AM:     publishOrigin: ui
11:02:50 AM: Caching artifacts
11:02:50 AM: Started saving node modules
11:02:50 AM: Finished saving node modules
11:02:50 AM: Started saving build plugins
11:02:50 AM: Finished saving build plugins
11:02:50 AM: Started saving pip cache
11:02:50 AM: Finished saving pip cache
11:02:50 AM: Started saving emacs cask dependencies
11:02:50 AM: Finished saving emacs cask dependencies
11:02:50 AM: Started saving maven dependencies
11:02:50 AM: Finished saving maven dependencies
11:02:50 AM: Started saving boot dependencies
11:02:50 AM: Finished saving boot dependencies
11:02:50 AM: Started saving rust rustup cache
11:02:50 AM: Finished saving rust rustup cache
11:02:50 AM: Started saving go dependencies
11:02:50 AM: Finished saving go dependencies
11:02:53 AM: Build failed due to a user error: Build script returned non-zero exit code: 2
11:02:53 AM: Creating deploy upload records
11:02:53 AM: Failing build: Failed to build site
11:02:54 AM: Failed during stage 'building site': Build script returned non-zero exit code: 2
11:02:54 AM: Finished processing build request in 54.003750505s

PLEASE help us help you by writing a good post!

  • we need to know your netlify site name. Example: gifted-antelope-58b104.netlify.app
  • DNS issues? Tell us the custom domain, tell us the error message! We can’t help if we don’t know your domain.
  • Build problems? Link or paste the FULL build log & build settings screenshot

The better the post - the faster the answer.

Hi @CristianVogel

Given webpack is the target of the build script, I believe it best listed as a dependency and not a dev dependency. If you have set NODE_ENV to production via an environment variable devDependencies are not loaded (see here.)

1 Like

Hi @coelmay
Thanks for helping. I find this a little confusing, because WebPack is the tool which is set to build the Production or Development app. Perhaps its the WebPack env that should be set to PRODUCTION not the NODE_ENV? is that what you are suggesting here?

Have you set the NODE_ENV via the Netlify UI as well as specifying it in the build script?

From the log:

and then

OK, thanks I figured it out by fiddling with a netlify.toml config file in the project root. Seems like I needed to change the publish root in the netlify settings to match the one being build by WebPack

1 Like