创建vue3+vite项目时报错TypeError: crypto.hash is not a function

本文章已经生成可运行项目,

在创建vue3+vite项目npm run dev启动项目时控制台报错TypeError: crypto.hash is not a function,原因是node版本不兼容,升到node版本22+,是正常运行的,想保持18.20.4的node版本需要一个补丁

diff --git a/dist/node/chunks/dep-Bsx9IwL8.js b/dist/node/chunks/dep-Bsx9IwL8.js
index 0583030d32a3a36aa13fbb2839435e5af6c0a9f4..43463dcb8c7a9cee2e44b29bc67902dcb360fa25 100644
--- a/dist/node/chunks/dep-Bsx9IwL8.js
+++ b/dist/node/chunks/dep-Bsx9IwL8.js
@@ -2830,8 +2830,16 @@ const singlelineCommentsRE = /\/\/.*/g;
 const requestQuerySplitRE = /\?(?!.*[/|}])/;
 const requestQueryMaybeEscapedSplitRE = /\\?\?(?!.*[/|}])/;
 const blankReplacer = (match) => " ".repeat(match.length);
+const hash =
+  // crypto.hash is supported in Node 21.7.0+, 20.12.0+
+  crypto.hash ??
+  ((
+    algorithm,
+    data,
+    outputEncoding,
+  ) => crypto.createHash(algorithm).update(data).digest(outputEncoding))
 function getHash(text, length = 8) {
-	const h$2 = crypto.hash("sha256", text, "hex").substring(0, length);
+	const h$2 = hash("sha256", text, "hex").substring(0, length);
 	if (length <= 64) return h$2;
 	return h$2.padEnd(length, "_");
 }

本文章已经生成可运行项目
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值