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
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
为搭建一个Vue3 TypeScript Vite项目,你可以按照以下步骤进行操作: 1. 首先,你需要掌握Vue3的基本使用。你可以参考我在Vue专栏中的《跟着官网学习Vue3》系列文章,这些文章应该能够帮助你基本掌握Vue3的使用方法。 2. 接下来,你可以考虑使用Pinia作为Vue的状态管理库,它可以满足小型项目的需求,并且使用简单。你可以尝试使用Pinia代替Vuex。 3. 在项目中使用windicss,它是一种轻量级的CSS框架,可以帮助你快速编写样式。 4. 最后,使用Vite作为打包工具,代替Webpack。Vite更加简单易用,而且天生支持许多类型的文件,比如SCSS文件,无需手动配置。如果你之前没有使用过Vite,也没有关系,通过学习一篇相关文章,你就能够掌握Vite的基本使用方法。 综上所述,你可以按照上述步骤来搭建一个Vue3 TypeScript Vite项目。希望对你有帮助!<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [一篇文章教小白学搭建 vite + ts + vue3 项目,手把手教程,不算我输](https://blog.csdn.net/qq_17335549/article/details/128480583)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值