????????此錯誤與 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
啟動項目?