skip to content
Wentao Zhang

解决 vuepress 无法编译打包

/ 1 min read

出现问题

打算使用vuepress做博客,项目结构以及配置都按官方文档设置,运行npm run docs:dev也是正常的,但是npm run docs:build打包的时候一直报错,下面是部分报错日志

Terminal window
(undefined) assets/js/styles.8f3dca9f.js from Terser
Error: error:0308010C:digital envelope routines::unsupported
at new Hash (node:internal/crypto/hash:69:19)
at Object.createHash (node:crypto:133:10)
at /Users/zhangwentao/vscode/notes/node_modules/terser-webpack-plugin/dist/index.js:217:37
at Array.forEach (<anonymous>)
at TerserPlugin.optimizeFn (/Users/zhangwentao/vscode/notes/node_modules/terser-webpack-plugin/dist/index.js:160:259)
at _next0 (eval at create (/Users/zhangwentao/vscode/notes/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:13:1)
at eval (eval at create (/Users/zhangwentao/vscode/notes/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:30:1)
(undefined) assets/js/1.7f771cfb.js from Terser

解决方法

有两种解决方法

  1. 降级node版本 经过验证node 16 版本下npm run docs:build 是正常的,在node 18版本下运行就会出现这个错误
  2. 设置环境变量(未验证) 具体的操作方式 https://github.com/webpack/webpack/issues/14532