问题现象
已经使用npx degit dcloudio/uni-preset-vue#vite-ts uni-app-vue3-ts
命令创建了一个项目。
再执行npm i -D @uni-helper/uni-app-types
命令,目的是为 Vue v3 uni-app 组件提供 TypeScript 类型,但报错:
D:\temp\HBuilderProjects\uni-app-vue3-ts>npm i -D @uni-helper/uni-app-types
npm error code ERESOLVE
npm error ERESOLVE unable to resolve dependency tree
npm error ERESOLVE unable to resolve dependency tree
npm error
npm error
npm error While resolving: uni-preset-vue@0.0.0
npm error While resolving: uni-preset-vue@0.0.0
npm error Found: typescript@4.9.5
npm error Found: typescript@4.9.5
npm error node_modules/typescript
npm error dev typescript@"^4.9.4" from the root project
npm error
npm error Could not resolve dependency:
npm error dev typescript@"^4.9.4" from the root project
npm error
npm error
npm error Could not resolve dependency:
npm error peer typescript@"^5.0.0" from @uni-helper/uni-app-types@1.0.0-alpha.4
npm error peer typescript@"^5.0.0" from @uni-helper/uni-app-types@1.0.0-alpha.4
npm error node_modules/@uni-helper/uni-app-types
npm error dev @uni-helper/uni-app-types@"*" from the root project
npm error
npm error Fix the upstream dependency conflict, or retry
npm error this command with --force or --legacy-peer-deps
npm error to accept an incorrect (and potentially broken) dependency resolution.
npm error
npm error
npm error For a full report see:
npm error D:\npm_repo\npm-cache\_logs\2024-09-11T11_58_17_606Z-eresolve-report.txt
npm error A complete log of this run can be found in: D:\npm_repo\npm-cache\_logs\2024-09-11T11_58_17_606Z-debug-0.log
npm error dev @uni-helper/uni-app-types@"*" from the root project
npm error
npm error Fix the upstream dependency conflict, or retry
npm error this command with --force or --legacy-peer-deps
npm error to accept an incorrect (and potentially broken) dependency resolution.
npm error
npm error
npm error For a full report see:
npm error D:\npm_repo\npm-cache\_logs\2024-09-11T11_58_17_606Z-eresolve-report.txt
npm error A complete log of this run can be found in: D:\npm_repo\npm-cache\_logs\2024-09-11T11_58_17_606Z-debug-0.log
npm error dev @uni-helper/uni-app-types@"*" from the root project
npm error
npm error Fix the upstream dependency conflict, or retry
npm error this command with --force or --legacy-peer-deps
npm error to accept an incorrect (and potentially broken) dependency resolution.
npm error
npm error
npm error For a full report see:
npm error D:\npm_repo\npm-cache\_logs\2024-09-11T11_58_17_606Z-eresolve-report.txt
npm error dev @uni-helper/uni-app-types@"*" from the root project
npm error
npm error Fix the upstream dependency conflict, or retry
npm error this command with --force or --legacy-peer-deps
npm error to accept an incorrect (and potentially broken) dependency resolution.
npm error
npm error
npm error For a full report see:
npm error D:\npm_repo\npm-cache\_logs\2024-09-11T11_58_17_606Z-eresolve-report.txt
npm error dev @uni-helper/uni-app-types@"*" from the root project
npm error
npm error Fix the upstream dependency conflict, or retry
npm error this command with --force or --legacy-peer-deps
npm error to accept an incorrect (and potentially broken) dependency resolution.
npm error dev @uni-helper/uni-app-types@"*" from the root project
npm error
npm error Fix the upstream dependency conflict, or retry
npm error dev @uni-helper/uni-app-types@"*" from the root project
npm error
npm error Fix the upstream dependency conflict, or retry
npm error dev @uni-helper/uni-app-types@"*" from the root project
npm error
npm error Fix the upstream dependency conflict, or retry
npm error dev @uni-helper/uni-app-types@"*" from the root project
npm error
npm error dev @uni-helper/uni-app-types@"*" from the root project
npm error dev @uni-helper/uni-app-types@"*" from the root project
npm error
npm error Fix the upstream dependency conflict, or retry
npm error this command with --force or --legacy-peer-deps
npm error to accept an incorrect (and potentially broken) dependency resolution.
npm error
npm error
npm error For a full report see:
npm error D:\npm_repo\npm-cache\_logs\2024-09-11T11_58_17_606Z-eresolve-report.txt
npm error A complete log of this run can be found in: D:\npm_repo\npm-cache\_logs\2024-09-11T11_58_17_606Z-debug-0.log
D:\temp\HBuilderProjects\uni-app-vue3-ts>
问题原因
npx degit dcloudio/uni-preset-vue#vite-ts
这个命令下载的模版中typescript版本低了,而@uni-helper/uni-app-types 要求v5 版本:
https://uni-typed.netlify.app/guide/uni-app-types.html#%E5%B7%B2%E6%9C%89%E9%A1%B9%E7%9B%AE
问题解决
@uni-helper/uni-app-types 官网的说明:
https://uni-typed.netlify.app/guide/uni-app-types.html#%E5%B7%B2%E6%9C%89%E9%A1%B9%E7%9B%AE
将项目package.json文件中"typescript": "^4.9.5",
这句话删掉:
然后执行npm install -D typescript
来安装新的版本:
安装完后,typescript已经是v5版本:
现在执行npm i -D @uni-helper/uni-app-types
:
安装完成后,package.json文件中更新了依赖: