nacos 2.3.0版本,在console-ui中按照readme上使用node v8.16.0
版本,npm run build 失败
ERROR in ./js/main.js from UglifyJs
Error: error:0308010C:digital envelope routines::unsupported
at new Hash (node:internal/crypto/hash:71:19)
at Object.createHash (node:crypto:133:10)
at /Users/esondeng/repository/shanshu/nacos-2.3.0/console-ui/node_modules/uglifyjs-webpack-plugin/dist/index.js:217:37
at Array.forEach ()
at UglifyJsPlugin.optimizeFn (/Users/esondeng/repository/shanshu/nacos-2.3.0/console-ui/node_modules/uglifyjs-webpack-plugin/dist/index.js:160:259)
at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/esondeng/repository/shanshu/nacos-2.3.0/console-ui/node_modules/tapable/lib/HookCodeFactory.js:33:10), :21:1)
at AsyncSeriesHook.lazyCompileHook (/Users/esondeng/repository/shanshu/nacos-2.3.0/console-ui/node_modules/tapable/lib/Hook.js:154:20)
at /Users/esondeng/repository/shanshu/nacos-2.3.0/console-ui/node_modules/webpack/lib/Compilation.js:1409:36
at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/esondeng/repository/shanshu/nacos-2.3.0/console-ui/node_modules/tapable/lib/HookCodeFactory.js:33:10), :6:1)
at AsyncSeriesHook.lazyCompileHook (/Users/esondeng/repository/shanshu/nacos-2.3.0/console-ui/node_modules/tapable/lib/Hook.js:154:20)
at /Users/esondeng/repository/shanshu/nacos-2.3.0/console-ui/node_modules/webpack/lib/Compilation.js:1405:32
at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/esondeng/repository/shanshu/nacos-2.3.0/console-ui/node_modules/tapable/lib/HookCodeFactory.js:33:10), :6:1)
at AsyncSeriesHook.lazyCompileHook (/Users/esondeng/repository/shanshu/nacos-2.3.0/console-ui/node_modules/tapable/lib/Hook.js:154:20)
at Compilation.seal (/Users/esondeng/repository/shanshu/nacos-2.3.0/console-ui/node_modules/webpack/lib/Compilation.js:1342:27)
at /Users/esondeng/repository/shanshu/nacos-2.3.0/console-ui/node_modules/webpack/lib/Compiler.js:675:18
at /Users/esondeng/repository/shanshu/nacos-2.3.0/console-ui/node_modules/webpack/lib/Compilation.js:1261:4
at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/esondeng/repository/shanshu/nacos-2.3.0/console-ui/node_modules/tapable/lib/HookCodeFactory.js:33:10), :24:1)
at AsyncSeriesHook.lazyCompileHook (/Users/esondeng/repository/shanshu/nacos-2.3.0/console-ui/node_modules/tapable/lib/Hook.js:154:20)
at Compilation.finish (/Users/esondeng/repository/shanshu/nacos-2.3.0/console-ui/node_modules/webpack/lib/Compilation.js:1253:28)
at /Users/esondeng/repository/shanshu/nacos-2.3.0/console-ui/node_modules/webpack/lib/Compiler.js:672:17
at _done (eval at create (/Users/esondeng/repository/shanshu/nacos-2.3.0/console-ui/node_modules/tapable/lib/HookCodeFactory.js:33:10), :9:1)
at eval (eval at create (/Users/esondeng/repository/shanshu/nacos-2.3.0/console-ui/node_modules/tapable/lib/HookCodeFactory.js:33:10), :32:22)
at /Users/esondeng/repository/shanshu/nacos-2.3.0/console-ui/node_modules/webpack/lib/Compilation.js:1185:12
at /Users/esondeng/repository/shanshu/nacos-2.3.0/console-ui/node_modules/webpack/lib/Compilation.js:1097:9
at process.processTicksAndRejections (node:internal/process/task_queues:77:11)
大家怎么解决的?
这个问题可能是由于Node.js版本与UglifyJS不兼容导致的。你可以尝试升级Node.js到更高版本,例如v10.0.0或更高,然后重新运行npm run build
。
如果你不想升级Node.js,可以尝试使用其他压缩插件替换UglifyJS,例如使用Terser插件。首先安装Terser插件:
npm install terser-webpack-plugin --save-dev
然后在webpack.config.js
文件中引入并配置Terser插件:
const TerserPlugin = require('terser-webpack-plugin');
module.exports = {
// ...
optimization: {
minimize: true,
minimizer: [new TerserPlugin()],
},
// ...
};
保存更改后,重新运行npm run build
,问题应该得到解决。
根据错误提示,问题出在uglifyjs-webpack-plugin插件不支持当前版本的Node.js。可以尝试以下方法解决:
nvm install 10.0.0
nvm use 10.0.0
yarn install
yarn run build
这样应该可以解决npm run build失败的问题。
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。