切换node版本


今天启动vue服务的时候遇到了以下报错

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 (/Users/chenshang/Work/Fly/web001/node_modules/webpack/lib/util/createHash.js:135:53)
    at Compilation.createHash (/Users/chenshang/Work/Fly/web001/node_modules/webpack/lib/Compilation.js:1918:16)
    at /Users/chenshang/Work/Fly/web001/node_modules/webpack/lib/Compilation.js:1386:9
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/chenshang/Work/Fly/web001/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
    at AsyncSeriesHook.lazyCompileHook (/Users/chenshang/Work/Fly/web001/node_modules/tapable/lib/Hook.js:154:20)
    at Compilation.seal (/Users/chenshang/Work/Fly/web001/node_modules/webpack/lib/Compilation.js:1342:27)
    at /Users/chenshang/Work/Fly/web001/node_modules/webpack/lib/Compiler.js:675:18
    at /Users/chenshang/Work/Fly/web001/node_modules/webpack/lib/Compilation.js:1261:4
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/chenshang/Work/Fly/web001/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:15:1)
    at AsyncSeriesHook.lazyCompileHook (/Users/chenshang/Work/Fly/web001/node_modules/tapable/lib/Hook.js:154:20)
    at Compilation.finish (/Users/chenshang/Work/Fly/web001/node_modules/webpack/lib/Compilation.js:1253:28)
    at /Users/chenshang/Work/Fly/web001/node_modules/webpack/lib/Compiler.js:672:17
    at eval (eval at create (/Users/chenshang/Work/Fly/web001/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:11:1)
    at /Users/chenshang/Work/Fly/web001/node_modules/webpack/lib/Compilation.js:1185:12 {
  opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ],
  library: 'digital envelope routines',
  reason: 'unsupported',
  code: 'ERR_OSSL_EVP_UNSUPPORTED'
}

按照 同事 给出的解决手段 在 package.json 中 使用 如下配置

"serve": "export NODE_OPTIONS=—openssl-legacy-provider;node scripts/config.js & npm run env && vue-cli-service serve",  
"build": "export NODE_OPTIONS=—openssl-legacy-provider;vue-cli-service build",

或者在环境变量里面单独 添加

export NODE_OPTIONS=—openssl-legacy-provide

还是无法解决问题,遂 打算降低 node 的版本尝试一下

全局安装 n 工具,是专门管理 node 版本的,可以用他来切换 node 的版本,当然还有其他工具也可以切换,自行百度就好,我用的是 n 工具。

npm install -g n       // 全局安装n
n                      // 查看Node.js版本列表
n <版本号>              // 安装指定版本的Node.js
n list                 // 切换当前使用的Node.js版本

记得使用 sudo 指令获取管理员权限


评论