npm run build 打包错误

错误信息:

Building for production...

ERROR Failed to compile with 25 errors 19:03:12
error

js/app.d3f0cc17.js from Terser
Error: error:0308010C:digital envelope routines::unsupported
at new Hash (node:internal/crypto/hash:71:19)
at Object.createHash (node:crypto:133:10)
at D:\develop\php\wamp\www\dingsheng_nstore\node_modules\terser-webpack-plugin\dist\index.js:217:37
at Array.forEach (<anonymous>)
at TerserPlugin.optimizeFn (D:\develop\php\wamp\www\dingsheng_nstore\node_modules\terser-webpack-plugin\dist\index.js:160:259)
at AsyncSeriesHook.eval [as callAsync] (eval at create (D:\develop\php\wamp\www\dingsheng_nstore\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:7:1)
at AsyncSeriesHook.lazyCompileHook (D:\develop\php\wamp\www\dingsheng_nstore\node_modules\tapable\lib\Hook.js:154:20)
at D:\develop\php\wamp\www\dingsheng_nstore\node_modules\webpack\lib\Compilation.js:1409:36
at AsyncSeriesHook.eval [as callAsync] (eval at create (D:\develop\php\wamp\www\dingsheng_nstore\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:6:1)
at AsyncSeriesHook.lazyCompileHook (D:\develop\php\wamp\www\dingsheng_nstore\node_modules\tapable\lib\Hook.js:154:20)
at D:\develop\php\wamp\www\dingsheng_nstore\node_modules\webpack\lib\Compilation.js:1405:32
at AsyncSeriesHook.eval [as callAsync] (eval at create (D:\develop\php\wamp\www\dingsheng_nstore\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:6:1)
at AsyncSeriesHook.lazyCompileHook (D:\develop\php\wamp\www\dingsheng_nstore\node_modules\tapable\lib\Hook.js:154:20)
at Compilation.seal (D:\develop\php\wamp\www\dingsheng_nstore\node_modules\webpack\lib\Compilation.js:1342:27)
at D:\develop\php\wamp\www\dingsheng_nstore\node_modules\webpack\lib\Compiler.js:675:18
at D:\develop\php\wamp\www\dingsheng_nstore\node_modules\webpack\lib\Compilation.js:1261:4
at AsyncSeriesHook.eval [as callAsync] (eval at create (D:\develop\php\wamp\www\dingsheng_nstore\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:24:1)
at AsyncSeriesHook.lazyCompileHook (D:\develop\php\wamp\www\dingsheng_nstore\node_modules\tapable\lib\Hook.js:154:20)
at Compilation.finish (D:\develop\php\wamp\www\dingsheng_nstore\node_modules\webpack\lib\Compilation.js:1253:28)
at D:\develop\php\wamp\www\dingsheng_nstore\node_modules\webpack\lib\Compiler.js:672:17
at _done (eval at create (D:\develop\php\wamp\www\dingsheng_nstore\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:9:1)
at eval (eval at create (D:\develop\php\wamp\www\dingsheng_nstore\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:32:22)
at D:\develop\php\wamp\www\dingsheng_nstore\node_modules\webpack\lib\Compilation.js:1185:12
at D:\develop\php\wamp\www\dingsheng_nstore\node_modules\webpack\lib\Compilation.js:1097:9
at process.processTicksAndRejections (node:internal/process/task_queues:77:11)

原因:

这个错误 error:0308010C:digital envelope routines::unsupported 通常发生在 Node.js 17+ 版本中,特别是当你尝试使用某些加密算法时。这个问题与 Node.js 在这些版本中更改了默认的 OpenSSL 配置有关,特别是与 OpenSSL 3 一起使用时。

解决方法:

    1. 设置环境变量:
      在启动 Node.js 进程之前,设置 NODE_OPTIONS 环境变量以使用旧版的 OpenSSL 兼容性模式。

      在 Windows 系统中,你可以这样做:

       
        set NODE_OPTIONS=--openssl-legacy-provider

      在 Unix 系统中(如 Linux 或 macOS),你可以这样做:

       
        export NODE_OPTIONS=--openssl-legacy-provider

      然后,再次运行你的构建命令。

posted @ 2024-06-05 19:18  幽暗天琴  阅读(9)  评论(0编辑  收藏  举报