vite构建vue3+TS项目及可能会遇见的问题

vite构建vue3项目

1、在要创建的文件夹位置单击右键打开PowerShell命令行工具

在这里插入图片描述
2、在PowerShell里面输入 npm init vite@latest
在这里插入图片描述
@latest是用最新的vite去构建
3、输入项目名字和包名 然后选择下面的vue
在这里插入图片描述
4、选择下面的TypeScript
在这里插入图片描述
5、一个vue3 + ts就创建好了
在这里插入图片描述

运行项目

打开刚构建好的项目文件夹,在项目文件夹中打开PowerShell,或者用vs code打开终端,输入npm install 下载项目所依赖的包,下载好之后输入npm run dev即可
在这里插入图片描述

可能会遇见的问题

1、输入启动命令后报错

(node:19596) UnhandledPromiseRejectionWarning: SyntaxError: Unexpected token '??='
    at Loader.moduleStrategy (internal/modules/esm/translators.js:145:18)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:19596) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:19596) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

这个时候去检查一下自己的node 版本 ??= 是node16版本以上才支持的,输入node -v看看自己是不是低于这个版本

2、打开项目发现TS类型报错,例如:

Cannot find module 'vue'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?
Property 'count' does not exist on type '{}'.

这个时候去找到tsconfig.json里面的moduleResolution这个选项,把bundler改成node,就已经好了
在这里插入图片描述
在这里插入图片描述
3、下载依赖的时候npm i 卡在 :#################] / reify:@esbuild/android-arm: timing reifyNode:node_modules/@esbuild/android-arm64 Completed in 45ms:
这个问题是淘宝的镜像源有一些问题,npm的默认镜像源又是淘宝导致的,这里可以换成cnpm,下载cnpm命令

npm install cnpm -g   
  • 10
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值