当前位置:   article > 正文

Mac的nodejs npm run build 报ERR_OSSL_EVP_UNSUPPORTED彻底解决办法

Mac的nodejs npm run build 报ERR_OSSL_EVP_UNSUPPORTED彻底解决办法

报错信息如下:

  1. Building for production...Error: error:0308010C:digital envelope routines::unsupported
  2. at new Hash (node:internal/crypto/hash:69:19)
  3. at Object.createHash (node:crypto:133:10)
  4. at module.exports (/Users/wanzhou/PhpstormProjects/HealthExam_Guide/frontend/manager/node_modules/webpack/lib/util/createHash.js:135:53)
  5. at NormalModule._initBuildHash (/Users/wanzhou/PhpstormProjects/HealthExam_Guide/frontend/manager/node_modules/webpack/lib/NormalModule.js:417:16)
  6. at handleParseError (/Users/wanzhou/PhpstormProjects/HealthExam_Guide/frontend/manager/node_modules/webpack/lib/NormalModule.js:471:10)
  7. at /Users/wanzhou/PhpstormProjects/HealthExam_Guide/frontend/manager/node_modules/webpack/lib/NormalModule.js:503:5
  8. at /Users/wanzhou/PhpstormProjects/HealthExam_Guide/frontend/manager/node_modules/webpack/lib/NormalModule.js:358:12
  9. at /Users/wanzhou/PhpstormProjects/HealthExam_Guide/frontend/manager/node_modules/loader-runner/lib/LoaderRunner.js:373:3
  10. at iterateNormalLoaders (/Users/wanzhou/PhpstormProjects/HealthExam_Guide/frontend/manager/node_modules/loader-runner/lib/LoaderRunner.js:214:10)
  11. at iterateNormalLoaders (/Users/wanzhou/PhpstormProjects/HealthExam_Guide/frontend/manager/node_modules/loader-runner/lib/LoaderRunner.js:221:10)
  12. at /Users/wanzhou/PhpstormProjects/HealthExam_Guide/frontend/manager/node_modules/loader-runner/lib/LoaderRunner.js:236:3
  13. at runSyncOrAsync (/Users/wanzhou/PhpstormProjects/HealthExam_Guide/frontend/manager/node_modules/loader-runner/lib/LoaderRunner.js:130:11)
  14. at iterateNormalLoaders (/Users/wanzhou/PhpstormProjects/HealthExam_Guide/frontend/manager/node_modules/loader-runner/lib/LoaderRunner.js:232:2)
  15. at Array.<anonymous> (/Users/wanzhou/PhpstormProjects/HealthExam_Guide/frontend/manager/node_modules/loader-runner/lib/LoaderRunner.js:205:4)
  16. at Storage.finished (/Users/wanzhou/PhpstormProjects/HealthExam_Guide/frontend/manager/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:55:16)
  17. at /Users/wanzhou/PhpstormProjects/HealthExam_Guide/frontend/manager/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:91:9
  18. ⠸ Building for production.../Users/wanzhou/PhpstormProjects/HealthExam_Guide/frontend/manager/node_modules/loader-runner/lib/LoaderRunner.js:114
  19. throw e;
  20. ^
  21. Error: error:0308010C:digital envelope routines::unsupported
  22. at new Hash (node:internal/crypto/hash:69:19)
  23. at Object.createHash (node:crypto:133:10)
  24. at module.exports (/Users/wanzhou/PhpstormProjects/HealthExam_Guide/frontend/manager/node_modules/webpack/lib/util/createHash.js:135:53)
  25. at NormalModule._initBuildHash (/Users/wanzhou/PhpstormProjects/HealthExam_Guide/frontend/manager/node_modules/webpack/lib/NormalModule.js:417:16)
  26. at handleParseError (/Users/wanzhou/PhpstormProjects/HealthExam_Guide/frontend/manager/node_modules/webpack/lib/NormalModule.js:471:10)
  27. at /Users/wanzhou/PhpstormProjects/HealthExam_Guide/frontend/manager/node_modules/webpack/lib/NormalModule.js:503:5
  28. at /Users/wanzhou/PhpstormProjects/HealthExam_Guide/frontend/manager/node_modules/webpack/lib/NormalModule.js:358:12
  29. at /Users/wanzhou/PhpstormProjects/HealthExam_Guide/frontend/manager/node_modules/loader-runner/lib/LoaderRunner.js:373:3
  30. at iterateNormalLoaders (/Users/wanzhou/PhpstormProjects/HealthExam_Guide/frontend/manager/node_modules/loader-runner/lib/LoaderRunner.js:214:10)
  31. at /Users/wanzhou/PhpstormProjects/HealthExam_Guide/frontend/manager/node_modules/loader-runner/lib/LoaderRunner.js:186:6
  32. at context.callback (/Users/wanzhou/PhpstormProjects/HealthExam_Guide/frontend/manager/node_modules/loader-runner/lib/LoaderRunner.js:111:13)
  33. at /Users/wanzhou/PhpstormProjects/HealthExam_Guide/frontend/manager/node_modules/cache-loader/dist/index.js:240:7
  34. at /Users/wanzhou/PhpstormProjects/HealthExam_Guide/frontend/manager/node_modules/neo-async/async.js:2830:7
  35. at done (/Users/wanzhou/PhpstormProjects/HealthExam_Guide/frontend/manager/node_modules/neo-async/async.js:2865:11)
  36. at /Users/wanzhou/PhpstormProjects/HealthExam_Guide/frontend/manager/node_modules/neo-async/async.js:2818:7
  37. at /Users/wanzhou/PhpstormProjects/HealthExam_Guide/frontend/manager/node_modules/cache-loader/dist/index.js:229:9 {
  38. opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ],
  39. library: 'digital envelope routines',
  40. reason: 'unsupported',
  41. code: 'ERR_OSSL_EVP_UNSUPPORTED'
  42. }

产生原因

由于你的node版本太高了,也可以降低版本,不过这不是一个优雅的解决办法

解决办法

添加环境变量即可解决,mac如何添加环境变量才有效果呢,windows如何解决这里不做描述了,网上太多教程了。打开Mac的命令终端执行如下命令:

vim ~/.zshrc

新增如下内容:

export NODE_OPTIONS=--openssl-legacy-provider

然后:wq 保存保存后执行重载配置命令:

source ~/.zshrc

总结

网上大部分教程是 sudo vim ~/.bash_profile 但是发现重启Mac后又不行了。所以推荐修改zsh的环境变量即可。

本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/242025
推荐阅读
相关标签
  

闽ICP备14008679号