webpack docker和react出错,数字信封例程::unsupported

pdtvr36n  于 2023-10-19  发布在  Webpack
关注(0)|答案(5)|浏览(124)

我参加了一个Docker课程,讲师提供了一个入门项目,里面有一些相当旧的React代码。
我对react项目进行了dockerized,这是一个简单的Dockerfile:

FROM node

WORKDIR /app

COPY package.json .

RUN npm i

COPY . .

EXPOSE 3000

CMD ["npm", "start"]

然后我建立了图像:

docker build -t goals-react .

并在附加模式下运行容器:

docker run --name goals-app --rm -p 3000:3000 goals-react

这是我收到的输出:

> [email protected] start
> react-scripts start

ℹ 「wds」: Project is running at http://172.17.0.4/
ℹ 「wds」: webpack output is served from
ℹ 「wds」: Content not from webpack is served from /app/public
ℹ 「wds」: 404s will fallback to /

Starting the development server...

Error: error:0308010C:digital envelope routines::unsupported
    at new Hash (node:internal/crypto/hash:67:19)      
    at Object.createHash (node:crypto:130: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 iterateNormalLoaders (/app/node_modules/loader-runner/lib/LoaderRunner.js:221:10)
/app/node_modules/react-scripts/scripts/start.js:19
  throw err;
  ^

Error: error:0308010C:digital envelope routines::unsupported
    at new Hash (node:internal/crypto/hash:67:19)      
    at Object.createHash (node:crypto:130: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 /app/node_modules/webpack/lib/NormalModule.js:452:10
    at /app/node_modules/webpack/lib/NormalModule.js:323:13
    at /app/node_modules/loader-runner/lib/LoaderRunner.js:367:11
    at /app/node_modules/loader-runner/lib/LoaderRunner.js:233:18
    at context.callback (/app/node_modules/loader-runner/lib/LoaderRunner.js:111:13)
    at /app/node_modules/babel-loader/lib/index.js:59:103 {
  opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ],
  library: 'digital envelope routines',
  reason: 'unsupported',
  code: 'ERR_OSSL_EVP_UNSUPPORTED'
}

Node.js v17.1.0

我假设这是因为react项目使用的是旧版本的react,所以我用以下命令upgraded the package.json文件:

npx npm-check-updates -u
npm install

然后我删除并重新创建了镜像,然后运行了一个新的容器:

docker rmi goals-react
docker build -t goals-react .
docker run --name goals-app --rm -p 3000:3000 goals-react

但令我惊讶的是,我收到了同样的错误。所以我在谷歌上搜索了digital envelope routines::unsupported,发现了另一个stackoverflow discussion
我执行了以下命令:

export NODE_OPTIONS=--openssl-legacy-provider

然后我重建了映像并重新启动了容器,但无济于事。我决定更彻底地阅读错误消息,它似乎是一个webpack错误。我去了webpack的github页面,我意识到其他人也有同样的问题,right here,但是这个问题已经解决了。他们还推荐了上面的命令,但显然对我不起作用。
提前感谢您的任何反馈和帮助。

编辑

根据@MikiBelavista的请求,这里是package.json文件:

{
  "name": "frontend",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^5.15.1",
    "@testing-library/react": "^12.1.2",
    "@testing-library/user-event": "^13.5.0",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-scripts": "4.0.3"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}
r6vfmomb

r6vfmomb1#

换句台词

"start": "react-scripts start",

"start": "react-scripts --openssl-legacy-provider start"

但要注意,OpenSSL实现的算法已被视为遗产。更多OpenSSl

nkhmeac6

nkhmeac62#

我也有同样的问题,我使用了n包并安装了node 16.13.1,这解决了我的问题!

wpcxdonn

wpcxdonn3#

将package.json“start”脚本更新为:

"start": "react-scripts --openssl-legacy-provider start"

请确保重新构建Docker镜像,否则您将获得相同的错误。

docker build --pull --rm -f "Dockerfile" -t yourappname:latest "."
pkln4tw6

pkln4tw64#

在2023年,一个被接受的解决方案不起作用,因为node镜像已经移动到debian 12,其中没有安装openssl 1.x.x,所以切换到旧的基础镜像是有意义的。

FROM node:18-bullseye
oxalkeyp

oxalkeyp5#

您应该使用Node的LTS版本,因为Node.js V17及以上版本将MD 4算法迁移到OpenSSL 3.0的遗留版本中。您应该在Dockerfile中的node选项中指定LTS版本,如下所示:

FROM node:16.15.0

目前16.15.0是LTS,请务必查看最新版本。不要忘记再次创建图像。添加--openssl-legacy-provide是不安全的。

相关问题