Build fails in Netlify, passes loccally, and in Github Actions

Build passes in Github actions here: https://github.com/cdierkens/bluebird-cabinetry-and-design/runs/842704183?check_suite_focus=true

Yet fails the preview deploy here: https://app.netlify.com/sites/bluebird-cabinetry-and-design/deploys/5f036f4f32dbc30008928907

Is it possible that lerna boostrap is not running from the postinstall hook?

Hey @cdierkens,
Yes, definitely possible! Looking into the deploy you linked, I’m seeing that the build starts in the web/ directory, so does not check or install anything from the root, including the build script in the root’s package.json. I’m seeing deploys fail with a similar error message going back to July 6 (https://app.netlify.com/sites/bluebird-cabinetry-and-design/deploys/5f035af50357939882bd359c), with the last successful production deploy from GitHub on June 9: https://app.netlify.com/sites/bluebird-cabinetry-and-design/deploys?page=2

This related thread about Lerna with Netlify might be useful:

Let us know if that helps or if we can offer other guidance.

The build script in the root delegates to each package in the monorepo, and each package should have its own dependencies listed correctly. That’s a good path to verify so thanks for pointing out that if a build starts in a directory, then that local package is used to install dependencies.

@jen The issue is still present. Each package in this monorepo defines it’s own dependencies, and Lerna simply delegates development tasks down to those packages, therefore Lerna is not needed for CI or building.

For example, here is a clean npm install and npm run build inside the web package on the master branch. No root directly node_modules or local node_modules exists prior to running.
➜ web git:(master) npm i && npm run build

> fsevents@1.2.13 install /Users/chris/Projects/bluebird-cabinetry-and-design/web/node_modules/fsevents
> node install.js

  SOLINK_MODULE(target) Release/.node
  CXX(target) Release/obj.target/fse/fsevents.o
  SOLINK_MODULE(target) Release/fse.node

> core-js@2.6.11 postinstall /Users/chris/Projects/bluebird-cabinetry-and-design/web/node_modules/core-js
> node -e "try{require('./postinstall')}catch(e){}"

Thank you for using core-js ( https://github.com/zloirock/core-js ) for polyfilling JavaScript standard library!

The project needs your help! Please consider supporting of core-js on Open Collective or Patreon: 
> https://opencollective.com/core-js 
> https://www.patreon.com/zloirock 

Also, the author of core-js ( https://github.com/zloirock ) is looking for a good job -)


> core-js-pure@3.6.4 postinstall /Users/chris/Projects/bluebird-cabinetry-and-design/web/node_modules/core-js-pure
> node -e "try{require('./postinstall')}catch(e){}"


> core-js@3.6.5 postinstall /Users/chris/Projects/bluebird-cabinetry-and-design/web/node_modules/gatsby/node_modules/core-js
> node -e "try{require('./postinstall')}catch(e){}"


> gatsby-telemetry@1.3.26 postinstall /Users/chris/Projects/bluebird-cabinetry-and-design/web/node_modules/gatsby-telemetry
> node src/postinstall.js || true


> gatsby-cli@2.12.74 postinstall /Users/chris/Projects/bluebird-cabinetry-and-design/web/node_modules/gatsby/node_modules/gatsby-cli
> node scripts/postinstall.js


> gatsby@2.24.29 postinstall /Users/chris/Projects/bluebird-cabinetry-and-design/web/node_modules/gatsby
> node scripts/postinstall.js

added 3183 packages from 1459 contributors and audited 3189 packages in 44.5s

158 packages are looking for funding
  run `npm fund` for details

found 1 high severity vulnerability
  run `npm audit fix` to fix them, or `npm audit` for details

> @bluebird/web@0.1.0 build /Users/chris/Projects/bluebird-cabinetry-and-design/web
> gatsby build

success open and validate gatsby-configs - 0.030s
success load plugins - 0.471s
success onPreInit - 0.004s
success delete html and css files from previous builds - 0.017s
info One or more of your plugins have changed since the last time you ran Gatsby. As
a precaution, we're deleting your site's cache to ensure there's no stale data.
success initialize cache - 0.030s
success copy gatsby files - 0.078s
info [sanity] Fetching remote GraphQL schema
info [sanity] Transforming to Gatsby-compatible GraphQL SDL
info [sanity] Stitching GraphQL schemas from SDL
success onPreBootstrap - 0.354s
success createSchemaCustomization - 0.015s
info [sanity] Fetching export stream for dataset
info [sanity] Done exporting!
success Checking for changed pages - 0.002s
success source and transform nodes - 0.613s
success building schema - 0.214s
success createPages - 0.012s
success Checking for changed pages - 0.001s
success createPagesStatefully - 0.076s
success update schema - 0.021s
success onPreExtractQueries - 0.003s
success extract queries from components - 0.424s
success write out redirect data - 0.002s
success onPostBootstrap - 0.001s
info bootstrap finished - 6.684s
success run static queries - 0.025s - 2/2 81.24/s
success run page queries - 0.016s - 9/9 551.87/s
success write out requires - 0.004s
warn Browserslist: caniuse-lite is outdated. Please run next command `npm update`
warn Browserslist: caniuse-lite is outdated. Please run next command `npm update`
warn chunk styles [mini-css-extract-plugin]
Conflicting order. Following module has been added:
* css ./node_modules/css-loader??ref--11-oneOf-1-1!./node_modules/postcss-loader/src??ref--11-oneOf-1-2!./node_modules/react-responsive-carousel/lib/styles/carous
el.min.css
despite it was not able to fulfill desired ordering with these modules:
* css ./node_modules/css-loader??ref--11-oneOf-0-1!./node_modules/postcss-loader/src??ref--11-oneOf-0-2!./src/components/Button/Button.module.css
  - couldn't fulfill desired order of chunk group(s) component---src-pages-portfolio-js
warn chunk styles [mini-css-extract-plugin]
Conflicting order. Following module has been added:
* css ./node_modules/css-loader??ref--11-oneOf-0-1!./node_modules/postcss-loader/src??ref--11-oneOf-0-2!./src/components/container.module.css
despite it was not able to fulfill desired ordering with these modules:
* css ./node_modules/css-loader??ref--11-oneOf-0-1!./node_modules/postcss-loader/src??ref--11-oneOf-0-2!./src/components/Button/Button.module.css
  - couldn't fulfill desired order of chunk group(s) component---src-pages-about-js, component---src-pages-contact-js, component---src-pages-index-js,
component---src-pages-portfolio-js, component---src-pages-services-js
warn chunk styles [mini-css-extract-plugin]
Conflicting order. Following module has been added:
* css ./node_modules/css-loader??ref--11-oneOf-0-1!./node_modules/postcss-loader/src??ref--11-oneOf-0-2!./src/components/Button/Button.module.css
despite it was not able to fulfill desired ordering with these modules:
* css ./node_modules/css-loader??ref--11-oneOf-0-1!./node_modules/postcss-loader/src??ref--11-oneOf-0-2!./src/components/PageTitle/PageTitle.module.css
  - couldn't fulfill desired order of chunk group(s) component---src-pages-404-js
  - while fulfilling desired order of chunk group(s) component---src-pages-about-js, component---src-pages-contact-js, component---src-pages-index-js,
success Building production JavaScript and CSS bundles - 27.617s
success Rewriting compilation hashes - 0.003s
success Building static HTML for pages - 7.614s - 9/9 1.18/s
info Generated public/sw.js, which will precache 6 files, totaling 283931 bytes.
The following pages will be precached:
/offline-plugin-app-shell-fallback/index.html
success onPostBuild - 0.061s
info Done building in 42.390807706 sec

@jen

The issue is still present. Does netlify set a working directory? The builds worked for quite some time and I did not change the project structure when it started failing.

Lerna in my case, simply delegates development tasks down to each package. There is no local sibling packages or anything complex. Each package states it’s own dependencies and can be npm install'd and built in isolation.

For example, the following is a clean install with no node_modules in the root or in any package. I am running from the master branch down in the web folder. If netlify has the same working directory, then is should fail the same way as the netlify build fails, however, it passes.

➜  web git:(master) npm i && npm run build

> fsevents@1.2.13 install /Users/chris/Projects/bluebird-cabinetry-and-design/web/node_modules/fsevents
> node install.js

  SOLINK_MODULE(target) Release/.node
  CXX(target) Release/obj.target/fse/fsevents.o
  SOLINK_MODULE(target) Release/fse.node

> core-js@2.6.11 postinstall /Users/chris/Projects/bluebird-cabinetry-and-design/web/node_modules/core-js
> node -e "try{require('./postinstall')}catch(e){}"

Thank you for using core-js ( https://github.com/zloirock/core-js ) for polyfilling JavaScript standard library!

The project needs your help! Please consider supporting of core-js on Open Collective or Patreon: 
> https://opencollective.com/core-js 
> https://www.patreon.com/zloirock 

Also, the author of core-js ( https://github.com/zloirock ) is looking for a good job -)


> core-js-pure@3.6.4 postinstall /Users/chris/Projects/bluebird-cabinetry-and-design/web/node_modules/core-js-pure
> node -e "try{require('./postinstall')}catch(e){}"


> core-js@3.6.5 postinstall /Users/chris/Projects/bluebird-cabinetry-and-design/web/node_modules/gatsby/node_modules/core-js
> node -e "try{require('./postinstall')}catch(e){}"


> gatsby-telemetry@1.3.26 postinstall /Users/chris/Projects/bluebird-cabinetry-and-design/web/node_modules/gatsby-telemetry
> node src/postinstall.js || true


> gatsby-cli@2.12.74 postinstall /Users/chris/Projects/bluebird-cabinetry-and-design/web/node_modules/gatsby/node_modules/gatsby-cli
> node scripts/postinstall.js


> gatsby@2.24.29 postinstall /Users/chris/Projects/bluebird-cabinetry-and-design/web/node_modules/gatsby
> node scripts/postinstall.js

added 3183 packages from 1459 contributors and audited 3189 packages in 44.5s

158 packages are looking for funding
  run `npm fund` for details

found 1 high severity vulnerability
  run `npm audit fix` to fix them, or `npm audit` for details

> @bluebird/web@0.1.0 build /Users/chris/Projects/bluebird-cabinetry-and-design/web
> gatsby build

success open and validate gatsby-configs - 0.030s
success load plugins - 0.471s
success onPreInit - 0.004s
success delete html and css files from previous builds - 0.017s
info One or more of your plugins have changed since the last time you ran Gatsby. As
a precaution, we're deleting your site's cache to ensure there's no stale data.
success initialize cache - 0.030s
success copy gatsby files - 0.078s
info [sanity] Fetching remote GraphQL schema
info [sanity] Transforming to Gatsby-compatible GraphQL SDL
info [sanity] Stitching GraphQL schemas from SDL
success onPreBootstrap - 0.354s
success createSchemaCustomization - 0.015s
info [sanity] Fetching export stream for dataset
info [sanity] Done exporting!
success Checking for changed pages - 0.002s
success source and transform nodes - 0.613s
success building schema - 0.214s
success createPages - 0.012s
success Checking for changed pages - 0.001s
success createPagesStatefully - 0.076s
success update schema - 0.021s
success onPreExtractQueries - 0.003s
success extract queries from components - 0.424s
success write out redirect data - 0.002s
success onPostBootstrap - 0.001s
info bootstrap finished - 6.684s
success run static queries - 0.025s - 2/2 81.24/s
success run page queries - 0.016s - 9/9 551.87/s
success write out requires - 0.004s
warn Browserslist: caniuse-lite is outdated. Please run next command `npm update`
warn Browserslist: caniuse-lite is outdated. Please run next command `npm update`
warn chunk styles [mini-css-extract-plugin]
Conflicting order. Following module has been added:
* css ./node_modules/css-loader??ref--11-oneOf-1-1!./node_modules/postcss-loader/src??ref--11-oneOf-1-2!./node_modules/react-responsive-carousel/lib/styles/carous
el.min.css
despite it was not able to fulfill desired ordering with these modules:
* css ./node_modules/css-loader??ref--11-oneOf-0-1!./node_modules/postcss-loader/src??ref--11-oneOf-0-2!./src/components/Button/Button.module.css
  - couldn't fulfill desired order of chunk group(s) component---src-pages-portfolio-js
warn chunk styles [mini-css-extract-plugin]
Conflicting order. Following module has been added:
* css ./node_modules/css-loader??ref--11-oneOf-0-1!./node_modules/postcss-loader/src??ref--11-oneOf-0-2!./src/components/container.module.css
despite it was not able to fulfill desired ordering with these modules:
* css ./node_modules/css-loader??ref--11-oneOf-0-1!./node_modules/postcss-loader/src??ref--11-oneOf-0-2!./src/components/Button/Button.module.css
  - couldn't fulfill desired order of chunk group(s) component---src-pages-about-js, component---src-pages-contact-js, component---src-pages-index-js,
component---src-pages-portfolio-js, component---src-pages-services-js
warn chunk styles [mini-css-extract-plugin]
Conflicting order. Following module has been added:
* css ./node_modules/css-loader??ref--11-oneOf-0-1!./node_modules/postcss-loader/src??ref--11-oneOf-0-2!./src/components/Button/Button.module.css
despite it was not able to fulfill desired ordering with these modules:
* css ./node_modules/css-loader??ref--11-oneOf-0-1!./node_modules/postcss-loader/src??ref--11-oneOf-0-2!./src/components/PageTitle/PageTitle.module.css
  - couldn't fulfill desired order of chunk group(s) component---src-pages-404-js
  - while fulfilling desired order of chunk group(s) component---src-pages-about-js, component---src-pages-contact-js, component---src-pages-index-js,
success Building production JavaScript and CSS bundles - 27.617s
success Rewriting compilation hashes - 0.003s
success Building static HTML for pages - 7.614s - 9/9 1.18/s
info Generated public/sw.js, which will precache 6 files, totaling 283931 bytes.
The following pages will be precached:
/offline-plugin-app-shell-fallback/index.html
success onPostBuild - 0.061s
info Done building in 42.390807706 sec

Even running npm install manually in the build config fails

From: https://app.netlify.com/sites/bluebird-cabinetry-and-design/deploys/5f2b2e5c8a41f60008582153
4:11:18 PM: ┌────────────────────────────────────┐
4:11:18 PM: │ 1. build.command from netlify.toml │
4:11:18 PM: └────────────────────────────────────┘
4:11:18 PM: ​
4:11:18 PM: $ npm install && npm run build
4:11:30 PM: audited 3189 packages in 12.164s
4:11:32 PM: 3 packages are looking for funding
4:11:32 PM: run npm fund for details
4:11:32 PM: found 1 high severity vulnerability
4:11:32 PM: run npm audit fix to fix them, or npm audit for details
4:11:32 PM: > @bluebird/web@0.1.0 build /opt/build/repo/web
4:11:32 PM: > gatsby build
4:11:32 PM: sh: 1: gatsby: not found

And proof that gatsby-cli is indeed in my dependecies

Hiya @cdierkens and sorry to be slow to get back to you! gatsby-cli (and a lot of other stuff that you’ll need with every build) seem to be in devDependencies - not dependencies. So we don’t install them if $NODE_ENV is set to a value of production, which yours is.

This is how npm works; you’ll need to either:

This is not specific to Netlify, tis just how npm works.

@fool Totally get how NPM works, however, these dependencies have always been in devDependencies.

Netlify must have change how NODE_ENV was set at some point.

I’ll accept this as a solution, and move my build time dependencies from devDependencies to dependencies