How to add --unhandled-rejections=strict

Hi! Is it possible to pass the --unhandled-rejections=strict flag to Node during the build? I want the build to fail when there’s an unhandled promise rejection.

You can set NPM_FLAGS environment variable: Build environment variables | Netlify Docs

Just to confirm: does this affect all Node scripts, not just npm install? The docs seem to say it’s only for npm install.

I would need the flag for Gatsby’s build process (npm run build)

I haven’t tried it but yes, according to the docs, it seems to work only for install command.

I think you can pass the flag in the command itself like, npm run build --unhandled-rejections=strict? Have you tried it?

Actually, no I haven’t tried modifying the build script itself. Too obvious :man_facepalming: :laughing:
Thanks again, I’ll try that!

Hmm, no luck so far. Not sure I’ve managed to put the CLI parameter in the right place, but it seemed to work locally at least.

Here’s a snippet of a recent failed build (full log), which Netlify thought was okay and tried to deploy:

1:24:13 PM: (node:1288) UnhandledPromiseRejectionWarning: Error: Command failed: DOCS_CONTENT_ROOT=../../ npx --unhandled-rejections=strict gatsby build --prefix-paths
1:24:13 PM:     at checkExecSyncError (child_process.js:630:11)
1:24:13 PM:     at execSync (child_process.js:666:15)
1:24:13 PM:     at /opt/build/repo/scripts/build-preview.js:50:3
1:24:13 PM:     at processTicksAndRejections (internal/process/task_queues.js:97:5)
1:24:13 PM: (node:1288) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see (rejection id: 1)
1:24:13 PM: (node:1288) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
1:24:13 PM: ​
1:24:13 PM: (build.command completed in 4m 44.8s)
1:24:13 PM: ​
1:24:13 PM: ────────────────────────────────────────────────────────────────
1:24:13 PM:   2. Deploy site                                                
1:24:13 PM: ────────────────────────────────────────────────────────────────
1:24:13 PM: ​
1:24:13 PM: Starting to deploy site from 'scripts/docs-app/public'
1:24:13 PM: Creating deploy tree 
1:24:13 PM: Creating deploy upload records
1:24:13 PM: 0 new files to upload
1:24:13 PM: 0 new functions to upload
1:24:13 PM: Site deploy was successfully initiated

I think I’ll open a new topic, with a more descriptive title, describing the problem, not a potential solution, and link back here.