I just got this error after adding my angular project to docker.
I used this command to the dockerize angular project:
docker build -t myProject:latest .
Dockerfile:
#stage 1
FROM node:latest as node
WORKDIR / app
COPY. .
RUN npm install
RUN npm run build
#stage 2
FROM nginx:alpine
COPY --from=node /app/dist/myProject /usr/share/nginx/html
and here is the error:
[+] Building 37.4s(9 / 9) FINISHED
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 232B 0.0s
=> [internal] load.dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for docker.io/library/node:latest 1.8s
=> [internal] load build context 2.6s
=> => transferring context: 4.04MB 2.5s
=> [1 / 5] FROM docker.io/library/node:latest @sha256:3e2e7e08f088c7c9c0c836622f725540ade205f10160a91dd3cc899170d410ef 0.0s
=> CACHED[2 / 5] WORKDIR /app 0.0s
=> [3/5] COPY. . 7.8s
=> [4/5] RUN npm install 15.4s
=> ERROR[5 / 5] RUN npm run build 9.9s
------
> [5/5] RUN npm run build:
#9 0.792
#9 0.792 > [email protected] build
#9 0.792 > ng build
#9 0.792
#9 2.803 - Generating browser application bundles (phase: setup)...
#9 9.807 node:internal/crypto/hash:67
#9 9.807 this[kHandle] = new _Hash(algorithm, xofLen);
#9 9.807 ^
#9 9.807
#9 9.807 Error: error:0308010C:digital envelope routines::unsupported
#9 9.807 at new Hash (node:internal/crypto/hash:67:19)
#9 9.807 at Object.createHash (node:crypto:133:10)
#9 9.807 at BulkUpdateDecorator.hashFactory (/app/node_modules/webpack/lib/util/createHash.js:145:18)
#9 9.807 at BulkUpdateDecorator.update (/app/node_modules/webpack/lib/util/createHash.js:46:50)
#9 9.807 at RawSource.updateHash (/app/node_modules/webpack/node_modules/webpack-sources/lib/RawSource.js:77:8)
#9 9.807 at NormalModule._initBuildHash (/app/node_modules/webpack/lib/NormalModule.js:880:17)
#9 9.807 at handleParseResult (/app/node_modules/webpack/lib/NormalModule.js:946:10)
#9 9.807 at /app/node_modules/webpack/lib/NormalModule.js:1040:4
#9 9.807 at processResult (/app/node_modules/webpack/lib/NormalModule.js:755:11)
#9 9.807 at /app/node_modules/webpack/lib/NormalModule.js:819:5 {
#9 9.807 opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ],
#9 9.807 library: 'digital envelope routines',
#9 9.807 reason: 'unsupported',
#9 9.807 code: 'ERR_OSSL_EVP_UNSUPPORTED'
#9 9.807 }
#9 9.807
#9 9.807 Node.js v18.2.0
------
executor failed running[/ bin / sh - c npm run build]: exit code: 1
PS D:dotnet Coreclient> set NODE_OPTIONS = --openssl - legacy - provider
PS D:dotnet Coreclient> docker build -t myprojectlient:latest.
[+] Building 15.0s (10/10) FINISHED
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 32B 0.0s
=> [internal] load.dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for docker.io/library/node:latest 3.1s
=> [auth] library / node:pull token for registry-1.docker.io 0.0s
=> [internal] load build context 3.2s
=> => transferring context: 4.04MB 3.1s
=> [1 / 5] FROM docker.io/library/node:latest @sha256:3e2e7e08f088c7c9c0c836622f725540ade205f10160a91dd3cc899170d410ef 0.0s
=> CACHED[2 / 5] WORKDIR /app 0.0s
=> CACHED[3 / 5] COPY . . 0.0s
=> CACHED[4 / 5] RUN npm install 0.0s
------
I found a solution that suggests downgrading the node version.
As you can see in the error message it’s mentioned v18.2.0 for Node.Js but I get v16.13.1 with node -v
.
3
Answers
To downgrade to node version 16, do
If using webpack 4 is needed, as the solution you’ve linked implies, then you need to make sure that’s what you’re referencing in your package.json and package-lock.json files.
The proper way of doing this unless you want to update your Angular framework to the latest version is to build with the
NODE_OPTIONS='--openssl-legacy-provider'
flag:See details here
On windows terminal you could use :
--max-old-space-size
is for big applications that require lots of RAM--openssl-legacy-provider
is to fix the problem related to this question.