vue3+vite+ts項(xiàng)目build時(shí)報(bào)了一大長(zhǎng)串錯(cuò)眼滤,錯(cuò)誤如下,有自己代碼的問(wèn)題樟澜,居然還有根本不是自己寫的倍靡,類似node_modules/@vue/runtime-core/dist/runtime-core.
這種里面的錯(cuò)誤,上網(wǎng)查詢+嘗試n久厢汹,終于解決了螟深,解決方法放在下面了。
src/components/doc/SwitchDemo.vue:15:26 - error TS2304: Cannot find name 'b
ool'.
15 <Switch v-model:value="bool"/>
~~~~
src/lib/Switch.vue:18:36 - error TS2304: Cannot find name 'value'.
18 <button :class="{'owl-checked':value}" @click="toggle" class="owl-sw
itch">
~~~~~
src/lib/Switch.vue:18:52 - error TS2304: Cannot find name 'toggle'.
18 <button :class="{'owl-checked':value}" @click="toggle" class="owl-sw
itch">
~~~~~~
src/components/doc/TabsDemo.vue:18:27 - error TS2304: Cannot find name 'ref
Selected'.
18 <Tabs v-model:selected="refSelected">
~~~~~~~~~~~
src/views/Doc.vue:18:20 - error TS2304: Cannot find name 'asideVisible'.
18 <aside v-if="asideVisible">
~~~~~~~~~~~~
src/lib/Button.vue:43:19 - error TS2304: Cannot find name 'classes'.
43 :class="classes"
~~~~~~~
src/lib/Button.vue:44:22 - error TS2304: Cannot find name 'disabled'.
44 :disabled="disabled">
~~~~~~~~
src/lib/Button.vue:45:17 - error TS2304: Cannot find name 'loading'.
45 <span v-if="loading" class="owl-loadingIndicator"></span>
~~~~~~~
src/lib/Dialog.vue:46:19 - error TS2304: Cannot find name 'visible'.
46 <template v-if="visible">
~~~~~~~
src/lib/Dialog.vue:48:47 - error TS2304: Cannot find name 'closeOnClickOver
lay'.
48 <div class="owl-dialog-overlay" @click="closeOnClickOverlay"></div
>
~~~~~~~~~~~~~~~~~~~
src/components/doc/DialogDemo.vue:43:19 - error TS2304: Cannot find name 't
oggle'.
43 <Button @click="toggle">toggle</Button>
~~~~~~
src/components/doc/DialogDemo.vue:44:28 - error TS2304: Cannot find name 'v
isible'.
44 <Dialog v-model:visible="visible"
~~~~~~~
src/components/Topnav.vue:46:17 - error TS2304: Cannot find name 'toggleMen
uButtonVisible'.
46 <span v-if="toggleMenuButtonVisible" class="toggleAside" @click="tog
gleAside">
~~~~~~~~~~~~~~~~~~~~~~~
src/components/doc/DialogDemo.vue:46:16 - error TS2304: Cannot find name 'o
k'.
46 :ok="ok"
~~
src/components/doc/DialogDemo.vue:47:20 - error TS2304: Cannot find name 'c
ancel'.
47 :cancel="cancel">
~~~~~~
src/components/Topnav.vue:46:70 - error TS2304: Cannot find name 'toggleAsi
de'.
46 <span v-if="toggleMenuButtonVisible" class="toggleAside" @click="tog
gleAside">
~~~
~~~~~~~~
src/components/doc/DialogDemo.vue:57:19 - error TS2304: Cannot find name 's
howDialog'.
57 <Button @click="showDialog">show</Button>
~~~~~~~~~~
src/lib/Dialog.vue:59:29 - error TS2304: Cannot find name 'ok'.
59 <Button @click="ok">確定</Button>
~~
src/lib/Dialog.vue:60:42 - error TS2304: Cannot find name 'cancel'.
60 <Button level="main" @click="cancel">關(guān)閉</Button>
~~~~~~
src/lib/Tabs.vue:57:38 - error TS2304: Cannot find name 'selected'.
57 :class="{selected:title===selected}"
~~~~~~~~
src/lib/Tabs.vue:58:20 - error TS2304: Cannot find name 'select'.
58 @click="select(title)"
~~~~~~
src/lib/Tabs.vue:59:36 - error TS2304: Cannot find name 'titles'.
59 v-for="(title,index) in titles"
~~~~~~
src/lib/Tabs.vue:60:36 - error TS2304: Cannot find name 'selected'.
60 :ref="el => {if(title===selected) selectedItem = el}"
~~~~~~~~
src/lib/Tabs.vue:60:46 - error TS2304: Cannot find name 'selectedItem'.
60 :ref="el => {if(title===selected) selectedItem = el}"
~~~~~~~~~~~~
src/lib/Tabs.vue:66:23 - error TS2304: Cannot find name 'current'.
66 <component :is="current" :key="current.props.title"/>
~~~~~~~
src/lib/Tabs.vue:66:38 - error TS2304: Cannot find name 'current'.
66 <component :is="current" :key="current.props.title"/>
~~~~~~~
node_modules/@vue/reactivity/dist/reactivity.d.ts:26:15 - error TS2748: Can
not access ambient const enums when the '--isolatedModules' flag is provide
d.
26 readonly [ReactiveFlags.IS_READONLY]: boolean;
~~~~~~~~~~~~~
node_modules/@vue/runtime-core/dist/runtime-core.d.ts:1225:6 - error TS2748
: Cannot access ambient const enums when the '--isolatedModules' flag is pr
ovided.
1225 [BooleanFlags.shouldCast]?: boolean;
~~~~~~~~~~~~
node_modules/@vue/runtime-core/dist/runtime-core.d.ts:1226:6 - error TS2748
: Cannot access ambient const enums when the '--isolatedModules' flag is pr
ovided.
1226 [BooleanFlags.shouldCastTrue]?: boolean;
~~~~~~~~~~~~
node_modules/@vue/runtime-core/dist/runtime-core.d.ts:1419:10 - error TS274
8: Cannot access ambient const enums when the '--isolatedModules' flag is p
rovided.
1419 export { ReactiveFlags }
~~~~~~~~~~~~~
node_modules/@vue/runtime-core/dist/runtime-core.d.ts:1775:10 - error TS274
8: Cannot access ambient const enums when the '--isolatedModules' flag is p
rovided.
1775 export { TrackOpTypes }
~~~~~~~~~~~~
node_modules/@vue/runtime-core/dist/runtime-core.d.ts:1804:10 - error TS274
8: Cannot access ambient const enums when the '--isolatedModules' flag is p
rovided.
1804 export { TriggerOpTypes }
~~~~~~~~~~~~~~
解決方法:
(一)node_modules/@vue/runtime-core/dist/runtime-core.
里面東西找不到這種不是自己代碼的錯(cuò)誤烫葬,在tsconfig.json文件中添加如圖:
"compilerOptions": {
"skipLibCheck": true,
}
(二)自己寫的代碼顯示Cannot find name 'xxxx'.
這種界弧,查了好久都沒(méi)找到解決方法凡蜻,最后官方的issues,找了同遭遇大佬的解答:
在package.json文件中垢箕,做如下修改:
// 刪除build后面的 vue-tsc --noEmit &&划栓,只留下vite build
"scripts": {
"build": "vite build",
},
然后就可以build了,完美解決啦~