NodeJS fails to compile for NuxtJS app

Previously working application suddenly stopped deploying successfully.
Looks like some sort of SSL/cryptography related library that fails to build in NodeJS…

This is the full log for the failure, starting from fly deploy

$ fly deploy
==> Verifying app config
--> Verified app config
==> Building image
Remote builder fly-builder-bitter-voice-5414 ready
==> Creating build context
--> Creating build context done
==> Building image with Docker
--> docker host: 20.10.12 linux x86_64
[+] Building 0.5s (0/1)
[+] Building 29.4s (8/10)
 => [internal] load remote build context                                                                                                                                               0.0s
 => copy /context /                                                                                                                                                                    0.1s
 => [internal] load metadata for docker.io/library/node:lts                                                                                                                            0.8s
 => [builder 1/6] FROM docker.io/library/node:lts@sha256:d09511bdb23ef545d385562689913f2b6ca82fdced95864e6cde709d91e42d26                                                              0.0s
 => CACHED [builder 2/6] WORKDIR /app                                                                                                                                                  0.0s
 => [builder 3/6] COPY . .                                                                                                                                                             0.1s
 => [builder 4/6] RUN yarn install   --prefer-offline   --frozen-lockfile   --non-interactive   --production=false                                                                    24.9s
 => ERROR [builder 5/6] RUN yarn build                                                                                                                                                 3.5s
------
 > [builder 5/6] RUN yarn build:
#8 0.478 yarn run v1.22.19
#8 0.506 $ nuxt build
#8 1.825 ℹ Production build
#8 1.826 ℹ Bundling for server and client side
#8 1.827 ℹ Target: server
#8 1.846 ℹ Using components loader to optimize imports
#8 1.846 ℹ Discovered Components: .nuxt/components/readme.md
#8 1.847 ✔ Builder initialized
#8 1.911 ✔ Nuxt files generated
#8 3.270 ℹ Compiling Client
#8 3.391 node:internal/crypto/hash:71
#8 3.391   this[kHandle] = new _Hash(algorithm, xofLen);
#8 3.391                   ^
#8 3.391
#8 3.391 Error: error:0308010C:digital envelope routines::unsupported
#8 3.391     at new Hash (node:internal/crypto/hash:71:19)
#8 3.391     at Object.createHash (node:crypto:133:10)
#8 3.391     at module.exports (/app/node_modules/webpack/lib/util/createHash.js:135:53)
#8 3.391     at NormalModule._initBuildHash (/app/node_modules/webpack/lib/NormalModule.js:417:16)
#8 3.391     at handleParseError (/app/node_modules/webpack/lib/NormalModule.js:471:10)
#8 3.391     at /app/node_modules/webpack/lib/NormalModule.js:503:5
#8 3.391     at /app/node_modules/webpack/lib/NormalModule.js:358:12
#8 3.391     at /app/node_modules/loader-runner/lib/LoaderRunner.js:373:3
#8 3.391     at iterateNormalLoaders (/app/node_modules/loader-runner/lib/LoaderRunner.js:214:10)
#8 3.391     at Array.<anonymous> (/app/node_modules/loader-runner/lib/LoaderRunner.js:205:4)
#8 3.391     at Storage.finished (/app/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:55:16)
#8 3.391     at /app/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:91:9
#8 3.391     at /app/node_modules/graceful-fs/graceful-fs.js:123:16
#8 3.391     at FSReqCallback.readFileAfterClose [as oncomplete] (node:internal/fs/read_file_context:68:3) {
#8 3.391   opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ],
#8 3.391   library: 'digital envelope routines',
#8 3.391   reason: 'unsupported',
#8 3.391   code: 'ERR_OSSL_EVP_UNSUPPORTED'
#8 3.391 }
#8 3.391
#8 3.391 Node.js v18.12.1
#8 3.420 error Command failed with exit code 1.
#8 3.420 info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
------
Error failed to fetch an image or build from source: error building: executor failed running [/bin/sh -c yarn build]: exit code: 1

It looks like there was a backwards incompatible security fix to openssl: node.js - Error message “error:0308010C:digital envelope routines::unsupported” - Stack Overflow

I encourage you to search that page for the word ‘Danger’. Many of the proposed fixes could leave your app vulnerable.

I had same issue and i’ve fixed by adding NODE_OPTIONS env var to the dockerfile generated by fly.io before building the nuxt app :

...
ENV NODE_OPTIONS=--openssl-legacy-provider
RUN yarn build 
....