vue3+vite+ts項(xiàng)目build時(shí)報(bào)錯(cuò)Cannot find name 'xxxx'.

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了,完美解決啦~

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末条获,一起剝皮案震驚了整個(gè)濱河市忠荞,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌帅掘,老刑警劉巖委煤,帶你破解...
    沈念sama閱讀 212,454評(píng)論 6 493
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異锄开,居然都是意外死亡素标,警方通過(guò)查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,553評(píng)論 3 385
  • 文/潘曉璐 我一進(jìn)店門萍悴,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái),“玉大人寓免,你說(shuō)我怎么就攤上這事癣诱。” “怎么了袜香?”我有些...
    開(kāi)封第一講書人閱讀 157,921評(píng)論 0 348
  • 文/不壞的土叔 我叫張陵撕予,是天一觀的道長(zhǎng)。 經(jīng)常有香客問(wèn)我蜈首,道長(zhǎng)实抡,這世上最難降的妖魔是什么? 我笑而不...
    開(kāi)封第一講書人閱讀 56,648評(píng)論 1 284
  • 正文 為了忘掉前任欢策,我火速辦了婚禮吆寨,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘踩寇。我一直安慰自己啄清,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 65,770評(píng)論 6 386
  • 文/花漫 我一把揭開(kāi)白布俺孙。 她就那樣靜靜地躺著辣卒,像睡著了一般。 火紅的嫁衣襯著肌膚如雪睛榄。 梳的紋絲不亂的頭發(fā)上荣茫,一...
    開(kāi)封第一講書人閱讀 49,950評(píng)論 1 291
  • 那天,我揣著相機(jī)與錄音场靴,去河邊找鬼啡莉。 笑死港准,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的票罐。 我是一名探鬼主播叉趣,決...
    沈念sama閱讀 39,090評(píng)論 3 410
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼该押!你這毒婦竟也來(lái)了疗杉?” 一聲冷哼從身側(cè)響起,我...
    開(kāi)封第一講書人閱讀 37,817評(píng)論 0 268
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤蚕礼,失蹤者是張志新(化名)和其女友劉穎烟具,沒(méi)想到半個(gè)月后,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體奠蹬,經(jīng)...
    沈念sama閱讀 44,275評(píng)論 1 303
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡朝聋,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,592評(píng)論 2 327
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了囤躁。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片冀痕。...
    茶點(diǎn)故事閱讀 38,724評(píng)論 1 341
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖狸演,靈堂內(nèi)的尸體忽然破棺而出言蛇,到底是詐尸還是另有隱情,我是刑警寧澤宵距,帶...
    沈念sama閱讀 34,409評(píng)論 4 333
  • 正文 年R本政府宣布腊尚,位于F島的核電站,受9級(jí)特大地震影響满哪,放射性物質(zhì)發(fā)生泄漏婿斥。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 40,052評(píng)論 3 316
  • 文/蒙蒙 一哨鸭、第九天 我趴在偏房一處隱蔽的房頂上張望民宿。 院中可真熱鬧,春花似錦兔跌、人聲如沸勘高。這莊子的主人今日做“春日...
    開(kāi)封第一講書人閱讀 30,815評(píng)論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)华望。三九已至,卻和暖如春仅乓,著一層夾襖步出監(jiān)牢的瞬間赖舟,已是汗流浹背。 一陣腳步聲響...
    開(kāi)封第一講書人閱讀 32,043評(píng)論 1 266
  • 我被黑心中介騙來(lái)泰國(guó)打工夸楣, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留宾抓,地道東北人子漩。 一個(gè)月前我還...
    沈念sama閱讀 46,503評(píng)論 2 361
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像石洗,于是被迫代替她去往敵國(guó)和親幢泼。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 43,627評(píng)論 2 350

推薦閱讀更多精彩內(nèi)容