创建以 typescript 开发的工程时出错
npx degit dcloudio/uni-preset-vue#vite-ts my-vue3-project
解决方案:
1.如果是创建vue3.0 + vite + javascript的uni-app项目,直接在浏览器打开 https://github.com/dcloudio/uni-preset-vue 切换到vite分支下载zip后缀的压缩文件,解压到本地就可以了。
2、如果是创建vue3.0 + vite + typescript的uni-app项目,直接在浏览器打开https://github.com/dcloudio/uni-preset-vue 切换到vite-ts分支下载zip后缀的压缩文件,解压到本地就可以了。
github中下载后,npm i安装项目依赖时报错:
PS D:\task\new-uniapp\medical-applet-master\medical-applet> npm i
npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: @dcloudio/vite-plugin-uni@3.0.0-alpha-3061420221216001
npm ERR! Found: vite@4.0.3
npm ERR! node_modules/vite
npm ERR! dev vite@"4.0.3" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer vite@"3.2.4" from @dcloudio/vite-plugin-uni@3.0.0-alpha-3061420221216001
npm ERR! node_modules/@dcloudio/vite-plugin-uni
npm ERR! dev @dcloudio/vite-plugin-uni@"3.0.0-alpha-3061420221216001" from the root project
npm ERR!
npm ERR! Conflicting peer dependency: vite@3.2.4
npm ERR! node_modules/vite
npm ERR! peer vite@"3.2.4" from @dcloudio/vite-plugin-uni@3.0.0-alpha-3061420221216001
npm ERR! node_modules/@dcloudio/vite-plugin-uni
npm ERR! dev @dcloudio/vite-plugin-uni@"3.0.0-alpha-3061420221216001" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!
npm ERR! See C:\Users\wm\AppData\Local\npm-cache\eresolve-report.txt for a full report.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\wm\AppData\Local\npm-cache\_logs\2023-08-23T06_11_49_285Z-debug-0.log
使用npm install --force或npm install --legacy-peer-deps
使用后安装依赖node_modules
PS D:\task\new-uniapp\medical-applet-master\medical-applet> npm install --legacy-peer-deps
npm WARN deprecated sourcemap-codec@1.4.8: Please use @jridgewell/sourcemap-codec instead
added 336 packages in 2m
35 packages are looking for funding
run `npm fund` for details
Cannot find name ‘require’. Do you need to install type definitions for node
"Cannot find name ‘require’. Do you need to install type definitions for node"这个错误通常是因为 TypeScript 编译器无法识别 Node.js 中使用的 ‘require’。