此错误与 Node.js 的加密模块有关,特别是在使用 OpenSSL 3.0 及以上版本时。Vue 项目在启动时可能会依赖一些旧的加密算法,而这些算法在 OpenSSL 3.0 中默认被禁用,导致 error:0308010C:digital envelope routines::unsupported
错误。
解决方法1:
1、删除 node_modules
和 package-lock.json
(或 yarn.lock
) ,也可手动删除
rm -rf node_modules package-lock.json
2、重新安装依赖
npm i
3、启动项目
方法2:降级 Node.js 版本
降级 Node.js 到 16.x 或更早的版本,这些版本默认使用 OpenSSL 1.1.x,不会出现这个问题。
1、使用 nvm
(来管理 Node.js 版本)
安装nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
安装 Node.js 16.x
nvm install 16
切换到 Node.js 16.x
nvm use 16
2、启动项目
方法3:
临时设置(仅对当前终端会话有效)
在终端中运行以下命令,然后启动项目
export NODE_OPTIONS=--openssl-legacy-provider
永久设置(对所有终端会话有效)
将环境变量添加到 shell 配置文件(如 .bashrc
、.zshrc
或 .bash_profile
)中
echo 'export NODE_OPTIONS=--openssl-legacy-provider' >> ~/.bashrc
然后重新加载配置文件
source ~/.bashrc
启动项目