vue-cli-service serve报错:error:0308010C:digital envelope routines::unsupported

升级 node 版本到 v18.3.0 后,执行 npm run dev 启动 vue-cli-service 本地开发服务报错:Error: error:0308010C:digital envelope routines::unsupported

一、完整报错信息

D:\project\data-web>npm run dev

> [email protected] dev
> vue-cli-service serve --mode dev

 INFO  Starting development server...
10% building 2/2 modules 0 activeError: error:0308010C:digital envelope routines::unsupported
    at new Hash (node:internal/crypto/hash:67:19)
    at Object.createHash (node:crypto:133:10)
    at module.exports (D:\project\datalk-web\node_modules\[email protected]@webpack\lib\util\createHash.js:135:53)
    at NormalModule._initBuildHash (D:\project\datalk-web\node_modules\[email protected]@webpack\lib\NormalModule.js:417:16)
    at handleParseError (D:\project\datalk-web\node_modules\[email protected]@webpack\lib\NormalModule.js:471:10)
    at D:\project\datalk-web\node_modules\[email protected]@webpack\lib\NormalModule.js:503:5
    at D:\project\datalk-web\node_modules\[email protected]@webpack\lib\NormalModule.js:358:12
    at D:\project\datalk-web\node_modules\[email protected]@loader-runner\lib\LoaderRunner.js:373:3
    at iterateNormalLoaders (D:\project\datalk-web\node_modules\[email protected]@loader-runner\lib\LoaderRunner.js:214:10)
    at iterateNormalLoaders (D:\project\datalk-web\node_modules\[email protected]@loader-runner\lib\LoaderRunner.js:221:10)
    at D:\project\datalk-web\node_modules\[email protected]@loader-runner\lib\LoaderRunner.js:236:3
    at runSyncOrAsync (D:\project\datalk-web\node_modules\[email protected]@loader-runner\lib\LoaderRunner.js:130:11)
    at iterateNormalLoaders (D:\project\datalk-web\node_modules\[email protected]@loader-runner\lib\LoaderRunner.js:232:2)
    at Array. (D:\project\datalk-web\node_modules\[email protected]@loader-runner\lib\LoaderRunner.js:205:4)
    at Storage.finished (D:\project\datalk-web\node_modules\[email protected]@enhanced-resolve\lib\CachedInputFileSystem.js:55:16)
    at D:\project\datalk-web\node_modules\[email protected]@enhanced-resolve\lib\CachedInputFileSystem.js:91:9
10% building 2/5 modules 3 active D:\project\datalk-web\node_modules\[email protected]@webpack-dev-server\client\index.js?http://0.0.0.0:80node: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:133:10)
    at module.exports (D:\project\datalk-web\node_modules\[email protected]@webpack\lib\util\createHash.js:135:53)
    at NormalModule._initBuildHash (D:\project\datalk-web\node_modules\[email protected]@webpack\lib\NormalModule.js:417:16)
    at handleParseError (D:\project\datalk-web\node_modules\[email protected]@webpack\lib\NormalModule.js:471:10)
    at D:\project\datalk-web\node_modules\[email protected]@webpack\lib\NormalModule.js:503:5
    at D:\project\datalk-web\node_modules\[email protected]@webpack\lib\NormalModule.js:358:12
    at D:\project\datalk-web\node_modules\[email protected]@loader-runner\lib\LoaderRunner.js:373:3
    at iterateNormalLoaders (D:\project\datalk-web\node_modules\[email protected]@loader-runner\lib\LoaderRunner.js:214:10)
    at Array. (D:\project\datalk-web\node_modules\[email protected]@loader-runner\lib\LoaderRunner.js:205:4)
    at Storage.finished (D:\project\datalk-web\node_modules\[email protected]@enhanced-resolve\lib\CachedInputFileSystem.js:55:16)
    at D:\project\datalk-web\node_modules\[email protected]@enhanced-resolve\lib\CachedInputFileSystem.js:91:9
    at D:\project\datalk-web\node_modules\[email protected]@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.3.0

二、解决办法

需要设置环境变量来解决

  1. Windows
set NODE_OPTIONS=--openssl-legacy-provider
  1. Linux / Mac
export NODE_OPTIONS=--openssl-legacy-provider

完成后,建议重开一个命令行窗口启动服务。


欢迎访问:天问博客

你可能感兴趣的:(大前端,vue.js,webpack,node.js,npm)