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

执行 yarn -devyarn serve 或者 npm run dev 时出现以下错误:

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:130:10)

该错误通常表示 OpenSSL 版本与您的 Node.js 版本不兼容。尽管您已经尝试将 Node.js 版本降级至 14.x,但问题仍然存在。在搜索了各种资料并尝试了各种方法后,您最终找到了解决方案。

解决方法是修改 package.json 文件,在相关构建命令之前添加以下内容:

对于 macOS 系统:

"scripts": {
    "serve": "export NODE_OPTIONS=--openssl-legacy-provider && vue-cli-service serve"
},

对于 Windows 系统:

"scripts": {
    "serve": "SET NODE_OPTIONS=--openssl-legacy-provider && vue-cli-service serve"
},

通过添加上述代码,您为构建命令设置了 NODE_OPTIONS 环境变量,使用了 --openssl-legacy-provider 选项来解决与 OpenSSL 版本不兼容的问题。这样,在执行相关构建命令时,将会自动应用这个环境变量设置。

无论是进行项目迭代还是团队开发,通过这种方法,您可以解决 OpenSSL 版本兼容性的问题,确保能够顺利执行相关构建命令。

猜你喜欢

转载自blog.csdn.net/weixin_45361998/article/details/131675867