美文网首页
Node.js v17版本npm run 报错 ERR_OSSL

Node.js v17版本npm run 报错 ERR_OSSL

作者: jiaxiaolei | 来源:发表于2022-04-27 17:20 被阅读0次

问题:

PS D:\jia__code\jia_lenovo_code\acm-frontend-ui> npm run start

> ant-design-pro@5.2.0 start
> cross-env UMI_ENV=dev umi dev

Bundle with webpack 5...
⏱️  MFSU Enabled
Starting the development server...

* Webpack █████████████████████████ building (10%) 0/1 entries 0/0 dependencies 0/0 modules 0 active

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

Error: error:0308010C:digital envelope routines::unsupported
    at new Hash (node:internal/crypto/hash:67:19)
    at Object.createHash (node:crypto:135:10)
    at BulkUpdateDecorator.hashFactory (D:\jia__code\jia_lenovo_code\acm-frontend-ui\node_modules\@umijs\deps\compiled\webpack\5\bundle5.js:184154:18)
    at BulkUpdateDecorator.digest (D:\jia__code\jia_lenovo_code\acm-frontend-ui\node_modules\@umijs\deps\compiled\webpack\5\bundle5.js:184089:21)
    at D:\jia__code\jia_lenovo_code\acm-frontend-ui\node_modules\@umijs\deps\compiled\webpack\5\bundle5.js:107234:49
    at done (D:\jia__code\jia_lenovo_code\acm-frontend-ui\node_modules\@umijs\deps\compiled\webpack\5\bundle5.js:38350:13)
    at D:\jia__code\jia_lenovo_code\acm-frontend-ui\node_modules\@umijs\deps\compiled\webpack\5\bundle5.js:180888:5
    at Hook.eval [as callAsync] (eval at create (D:\jia__code\jia_lenovo_code\acm-frontend-ui\node_modules\@umijs\deps\compiled\webpack\5\bundle5.js:50186:10), <anonymous>:6:1)
    at AsyncQueue._handleResult (D:\jia__code\jia_lenovo_code\acm-frontend-ui\node_modules\@umijs\deps\compiled\webpack\5\bundle5.js:180858:21)
    at D:\jia__code\jia_lenovo_code\acm-frontend-ui\node_modules\@umijs\deps\compiled\webpack\5\bundle5.js:180841:11
    at D:\jia__code\jia_lenovo_code\acm-frontend-ui\node_modules\@umijs\deps\compiled\webpack\5\bundle5.js:107076:4
    at callback (D:\jia__code\jia_lenovo_code\acm-frontend-ui\node_modules\@umijs\deps\compiled\webpack\5\bundle5.js:34510:20)
    at FSReqCallback.oncomplete (node:fs:200:5) {
  opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ],
  library: 'digital envelope routines',
  reason: 'unsupported',
  code: 'ERR_OSSL_EVP_UNSUPPORTED'
}

Node.js v17.9.0

解决:

出现这个错误是因为 node.js V17版本中最近发布的OpenSSL3.0,

而OpenSSL3.0对允许算法和密钥大小增加了严格的限制,可能会对生态系统造成一些影响.

在node.js V17以前一些可以正常运行的的应用程序,但是在 V17 版本可能会抛出以下异常:

方法1: 做配置(推荐)

在package.json 中进行配置,举例:
"scripts": {
   "start": "SET NODE_OPTIONS=--openssl-legacy-provider && react-scripts start",
   "build": "SET NODE_OPTIONS=--openssl-legacy-provider && react-scripts build"
},

方法2: 降低版本

I just got this error, it seems that you are using Node version 17+. It is not compatible with some webpack stuff yet.

Try using LTS version instead, currently at 16.13.0.

方法3:.临时解决,设置环境变量 (测试无效)

#windows下
set NODE_OPTIONS=--openssl-legacy-provider
#linux下
export NODE_OPTIONS=--openssl-legacy-provider

相关文章

网友评论

      本文标题:Node.js v17版本npm run 报错 ERR_OSSL

      本文链接:https://www.haomeiwen.com/subject/jrjlyrtx.html