【REACT18.x】使用vite创建的项目无法启动,报错TypeError: crypto.hash is not a function解决方法
在使用vite创建新项目的时候,出现这种运行不了的报错解决方法
报错信息
TypeError: crypto.hash is not a functionat getHash (file:///D:/mine/reactrouter6app/node_modules/.pnpm/vite@7.0.6/node_modules/vite/dist/node/chunks/dep-BHkUv4Z8.js:2788:21)at getLockfileHash (file:///D:/mine/reactrouter6app/node_modules/.pnpm/vite@7.0.6/node_modules/vite/dist/node/chunks/dep-BHkUv4Z8.js:11673:9)at getDepHash (file:///D:/mine/reactrouter6app/node_modules/.pnpm/vite@7.0.6/node_modules/vite/dist/node/chunks/dep-BHkUv4Z8.js:11676:23)
- 确保node版本在20.x以上, 一直以为只要18.x就可以了,谁知道node更新的太快了
目前node可用的版本都在24.5了 - 使用nvm直接安装最新的版本就可以
- 删除之前的node_modules,重新执行
pnpm install
这样就运行成功了