用yarn build 来打包项目,发现开始疯狂报错
PS D:\sx1\xiaochajian\vue3-h5-template> yarn build
yarn run v1.22.19
$ vue-cli-service build
postcss-px-to-viewport: postcss.plugin was deprecated. Migration guide:
https://evilmartians.com/chronicles/postcss-8-plugin-migration
Browserslist: caniuse-lite is outdated. Please run:
npx browserslist@latest --update-db
Why you should do it regularly:
https://github.com/browserslist/browserslist#browsers-data-updating
| Building for production...[@vue/compiler-sfc] the >>> and /deep/ combinators have been deprecated. Use :deep() instead.
| Building for production...
ERROR Failed to compile with 1 error 17:05:36
error in ./src/views/result/defeat.vue?vue&type=script&setup=true&lang=ts
Module parse failed: Unexpected token (22:12)
File was processed with these loaders:
* ./node_modules/cache-loader/dist/cjs.js
* ./node_modules/vue-loader-v16/dist/index.js
You may need an additional loader to handle the result of these loaders.
|
|
> return (_ctx: any,_cache: any) => {
| const _component_van_image = _resolveComponent("van-image")
| const _component_van_button = _resolveComponent("van-button")
@ ./src/views/result/defeat.vue?vue&type=script&setup=true&lang=ts 1:0-194 1:0-194 1:195-378 1:195-378
@ ./src/views/result/defeat.vue
@ ./src/router/routes.js
@ ./src/router/index.js
@ ./src/main.js
@ multi ./src/main.js
ERROR Build failed with errors.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
发现原因是声明了,lang=“ts”
<script setup lang="ts">
由于引用的是模板,所以开始对比查看之前TS运行正常的项目和此项目的不同之处。
发现在package.json
中typescript在报错项目中根本没有,仔细查看了文档,发现没有ts的内容
改动代码内容后,yarn build 正常
引用模板之前,一定要仔细阅读文档。