1.問題原因
升級了Node.js v17+ 版本出現(xiàn)的問題。
2.錯(cuò)誤描述
升級了node.js 版本到 v17.9.1,出現(xiàn)如下錯(cuò)誤:
Error: error:0308010C:digital envelope routines::unsupported
at new Hash (node:internal/crypto/hash:67:19)
at Object.createHash (node:crypto:135:10)
at module.exports (H:\iWork\產(chǎn)品代碼\前端代碼\ui_1\node_modules\webpack\lib\util\createHash.js:135:53)
at NormalModule._initBuildHash (H:\iWork\產(chǎn)品代碼\前端代碼\ui_1\node_modules\webpack\lib\NormalModule.js:417:16)
at handleParseError (H:\iWork\產(chǎn)品代碼\前端代碼\ui_1\node_modules\webpack\lib\NormalModule.js:471:10)
at H:\iWork\產(chǎn)品代碼\前端代碼\ui_1\node_modules\webpack\lib\NormalModule.js:503:5
at H:\iWork\產(chǎn)品代碼\前端代碼\ui_1\node_modules\webpack\lib\NormalModule.js:358:12
at H:\iWork\產(chǎn)品代碼\前端代碼\ui_1\node_modules\loader-runner\lib\LoaderRunner.js:373:3
at Storage.finished (H:\iWork\產(chǎn)品代碼\前端代碼\ui_1\node_modules\enhanced-resolve\lib\CachedInputFileSystem.js:55:16)
at H:\iWork\產(chǎn)品代碼\前端代碼\ui_1\node_modules\enhanced-resolve\lib\CachedInputFileSystem.js:91:9
at H:\iWork\產(chǎn)品代碼\前端代碼\ui_1\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'
}
3.解決辦法
如果使用的是 visual studio code,在終端處輸入
windows 輸入
$env:NODE_OPTIONS="--openssl-legacy-provider"
或
set NODE_OPTIONS=--openssl-legacy-provider
補(bǔ)充:
在終端輸入一次只能本次生效,如果想永久生效可以在 package.json 文件中修改對應(yīng)的 scripts 節(jié)點(diǎn)的內(nèi)容如下:
"serve": "SET NODE_OPTIONS=--openssl-legacy-provider && vue-cli-service serve",
"build": "SET NODE_OPTIONS=--openssl-legacy-provider && vue-cli-service build",
linux 輸入
export NODE_OPTIONS=--openssl-legacy-provider
最直接的辦法
將 node.js 版本降到 v14