今天在初始化項(xiàng)目中,出現(xiàn)了一個(gè)奇怪的情況:明明路徑是對(duì)的,但是編譯的時(shí)候,一直報(bào)“This dependency was not found”的錯(cuò)。
代碼如下:
import Vue from 'vue' import App from './App' import router from './router' import 'common/stylus/index.styl' /* eslint-disable no-new */ new Vue({ el: '#app', render: h => h(App) })
控制臺(tái)一直報(bào)錯(cuò),表示無(wú)法找到common/stylus/index.styl
,然而,路徑是通過(guò)ide補(bǔ)全填寫(xiě)的,不可能出現(xiàn)錯(cuò)誤,那又是為什么?
在網(wǎng)上多番搜索發(fā)現(xiàn),Vue中的引入文件時(shí),需要通過(guò)./通知編譯器是在當(dāng)前路徑,不然的話,第一個(gè)文件夾名會(huì)被認(rèn)為是webpack配置的alias(別名)。
所以,正確引入index.styl的方式是:
import Vue from 'vue' import App from './App' import router from './router' import './common/stylus/index.styl' // 添加./避免編譯器認(rèn)為是別名 /* eslint-disable no-new */ new Vue({ el: '#app', render: h => h(App) })
總結(jié)
以上所述是小編給大家介紹的Vue中"This dependency was not found"的問(wèn)題的解決方法,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
聲明:本網(wǎng)頁(yè)內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問(wèn)題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com