[npm] npm打包/运行时,报:"95% emitting CompressionPlugin ERROR Error: error:0308010C:digital envelope routines::unsupported"

1 问题描述

  • 环境信息
  • windows 10
  • node : v20.11.1
> node --version
v20.11.1
  • vue : 2.6.12
[dependencies]
"vue": "2.6.12"
"vue-count-to": "1.0.13"
"vue-cropper": "0.5.5"
"vue-meta": "2.4.0"
"vue-router": "3.4.9"
"vuedraggable": "2.24.3"
"vuex": "3.6.0"
...

[devDependencies]
"@vue/cli-plugin-babel": "4.4.6"
"@vue/cli-plugin-eslint": "4.4.6"
"@vue/cli-service": "4.4.6"
"vue-template-compiler": "2.6.12"
...
  • 执行npm run dev报错

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

(base) PS E:\xxx\Gitee-Projects\RuoYi-Vue-Plus\ruoyi-ui> npm run dev

> ruoyi@3.8.7 dev
> vue-cli-service serve

 INFO  Starting development server...
95% emitting CompressionPlugin ERROR  Error: error:0308010C:digital envelope routines::unsupported
Error: error:0308010C:digital envelope routines::unsupported
    at new Hash (node:internal/crypto/hash:68:19)
    at Object.createHash (node:crypto:138:10)
    at E:\xxxx\Gitee-Projects\RuoYi-Vue-Plus\ruoyi-ui\node_modules\compression-webpack-plugin\dist\index.js:243:42
    at CompressionPlugin.compress (E:\xxxx\Gitee-Projects\RuoYi-Vue-Plus\ruoyi-ui\node_modules\compression-webpack-plugin\dist\index.js:284:9)
    at E:\xxxx\Gitee-Projects\RuoYi-Vue-Plus\ruoyi-ui\node_modules\compression-webpack-plugin\dist\index.js:305:12
    at _next1 (eval at create (E:\xxxx\Gitee-Projects\RuoYi-Vue-Plus\ruoyi-ui\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:14:17)
    at eval (eval at create (E:\xxxx\Gitee-Projects\RuoYi-Vue-Plus\ruoyi-ui\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:33:1)
    at E:\xxxx\Gitee-Projects\RuoYi-Vue-Plus\ruoyi-ui\node_modules\copy-webpack-plugin\dist\index.js:91:9
(

2 问题分析

  • 这个错误是由于在Vue项目中使用了CompressionPlugin插件而引起的。

具体错误信息是"95% emitting CompressionPlugin ERROR Error: error:0308010C:digital envelope routines::unsupported"。
根据引用,这个错误与OpenSSL版本有关。

  • node.js V17版本中最近发布的OpenSSL3.0允许算法密钥大小增加了严格的限制,可能会对生态系统造成一些影响。

因此,可能是由于OpenSSL3.0的限制导致CompressionPlugin插件在构建过程中出现了错误。

  • 解决这个问题的方法之一是在构建命令中设置一个环境变量,以使用旧版本的OpenSSL

根据引用,可以在构建命令中添加以下内容:"build:prod": "SET NODE_OPTIONS=--openssl-legacy-provider && vue-cli-service build"
这样设置后,构建命令将使用旧版本的OpenSSL,从而解决了该错误。请确保在使用该命令时,将其替换为实际使用的命令。

  • 另外,引用提到了一种方法,即通过打开终端、并按照说明粘贴一些命令来解决该问题。

但是由于这个方法不一定适用于所有情况,所以可能需要尝试其他解决方案。

  • 总结起来,95% emitting CompressionPlugin ERROR Error: error:0308010C:digital envelope routines::unsupported错误是由于OpenSSL 3.0限制导致CompressionPlugin插件在构建过程中出现了错误。

解决该问题的方法之一是在构建命令中设置一个环境变量,使用旧版本的OpenSSL。另外,还可以尝试其他解决方案,如引用中提到的方法。

3 解决方法

  • package.json - scripts :
  ...
 "dev": "SET NODE_OPTIONS=--openssl-legacy-provider && vue-cli-service serve",
  ...

完整配置:如下

...
  "scripts": {
    "dev": "SET NODE_OPTIONS=--openssl-legacy-provider && vue-cli-service serve",
    "build:prod": "vue-cli-service build",
    "build:stage": "vue-cli-service build --mode staging",
    "preview": "node build/index.js --preview",
    "lint": "eslint --ext .js,.vue src"
  },
...

X 参考文献

posted @ 2024-03-18 12:49  千千寰宇  阅读(124)  评论(0编辑  收藏  举报