1

I try to build a Docker image executing the code:

docker build . -t <YOUR_DOCKER_HUB_USERNAME>/my-nuxt-project

It is about a nuxt.js project but when I run the code I receive the following error:

Step 5/13 : RUN yarn build
 ---> Running in 4dd3684952ba
yarn run v1.22.19
$ nuxt build
ℹ Production build
ℹ Bundling for server and client side
ℹ Target: server
ℹ Using components loader to optimize imports
ℹ Discovered Components: .nuxt/components/readme.md
✔ Builder initialized
✔ Nuxt files generated
ℹ Compiling Client

node:internal/crypto/hash:71
  this[kHandle] = new _Hash(algorithm, xofLen);
                  ^

Error: error:0308010C:digital envelope routines::unsupported
    at new Hash (node:internal/crypto/hash:71:19)
    at Object.createHash (node:crypto:133:10)
    at module.exports (/app/node_modules/webpack/lib/util/createHash.js:135:53)
    at NormalModule._initBuildHash (/app/node_modules/webpack/lib/NormalModule.js:417:16)
    at handleParseError (/app/node_modules/webpack/lib/NormalModule.js:471:10)
    at /app/node_modules/webpack/lib/NormalModule.js:503:5
    at /app/node_modules/webpack/lib/NormalModule.js:358:12
    at /app/node_modules/loader-runner/lib/LoaderRunner.js:373:3
    at iterateNormalLoaders (/app/node_modules/loader-runner/lib/LoaderRunner.js:214:10)
    at Array.<anonymous> (/app/node_modules/loader-runner/lib/LoaderRunner.js:205:4)
    at Storage.finished (/app/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:55:16)
    at /app/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:91:9
    at /app/node_modules/graceful-fs/graceful-fs.js:123:16
    at FSReqCallback.readFileAfterClose [as oncomplete] (node:internal/fs/read_file_context:68:3) {
  opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ],
  library: 'digital envelope routines',
  reason: 'unsupported',
  code: 'ERR_OSSL_EVP_UNSUPPORTED'
}

Node.js v18.12.0
error Command failed with exit code 1.

This is the Dockerfile that I am using. I am following the nuxt documentation to build the image.

FROM node:lts as builder

WORKDIR /app

COPY . .

RUN yarn install \
  --prefer-offline \
  --frozen-lockfile \
  --non-interactive \
  --production=false

RUN yarn build

RUN rm -rf node_modules && \
  NODE_ENV=production yarn install \
  --prefer-offline \
  --pure-lockfile \
  --non-interactive \
  --production=true

FROM node:lts

WORKDIR /app

COPY --from=builder /app  .

ENV HOST 0.0.0.0
EXPOSE 3000

CMD [ "yarn", "start" ]

Anyone knows how to debug it?

João Denari
  • 111
  • 1
  • 7
  • 1
    Does this help you? https://stackoverflow.com/questions/69692842/error-message-error0308010cdigital-envelope-routinesunsupported – Dulaj Ariyaratne Oct 27 '22 at 13:01
  • No, it did not work! I added the instructions within scripts, but the same error appeared "scripts": { "dev": "nuxt", "build": "nuxt --openssl-legacy-provider build", "start": "nuxt --openssl-legacy-provider start", "generate": "nuxt --openssl-legacy-provider generate", "test": "jest" }, – João Denari Oct 27 '22 at 13:18

1 Answers1

6

Try adding NODE_OPTIONS=--openssl-legacy-provider as docker environment variable. So your Dockerfile should be like this. Try rebuilding your Dockerfile after this change.

FROM node:lts as builder

WORKDIR /app

ENV NODE_OPTIONS=--openssl-legacy-provider

COPY . .

RUN yarn install \
  --prefer-offline \
  --frozen-lockfile \
  --non-interactive \
  --production=false

RUN yarn build

RUN rm -rf node_modules && \
  NODE_ENV=production yarn install \
  --prefer-offline \
  --pure-lockfile \
  --non-interactive \
  --production=true

FROM node:lts

WORKDIR /app

COPY --from=builder /app  .

ENV HOST 0.0.0.0
EXPOSE 3000

CMD [ "yarn", "start" ]
Dulaj Ariyaratne
  • 998
  • 1
  • 6
  • 13
  • 1
    Hi, Dulaj Thanks a lot! It is working perfectly The container is running ;) – João Denari Oct 27 '22 at 14:51
  • Got below error @Dulaj ```=> ERROR [3/9] RUN yarn install --prefer-offline --frozen-lockfile --non-interactive --production=false 0.2s ------ > [3/9] RUN yarn install --prefer-offline --frozen-lockfile --non-interactive --production=false: #5 0.196 + yarn install --prefer-offline --frozen-lockfile --non-interactive --production=false #5 0.208 /bin/bash: line 1: yarn: command not found ``` – Karthik Feb 23 '23 at 15:16
  • What is the image that you are using? @Karthik – Dulaj Ariyaratne Feb 24 '23 at 12:35