今天在初始化項目中,出現了一個奇怪的情況:明明路徑是對的,但是編譯的時候,一直報“This dependency was not found”的錯。
代碼如下:
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)})控制臺一直報錯,表示無法找到common/stylus/index.styl,然而,路徑是通過ide補全填寫的,不可能出現錯誤,那又是為什么?
在網上多番搜索發現,Vue中的引入文件時,需要通過./通知編譯器是在當前路徑,不然的話,第一個文件夾名會被認為是webpack配置的alias(別名)。
所以,正確引入index.styl的方式是:
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)})總結
以上所述是小編給大家介紹的Vue中"This dependency was not found"的問題的解決方法,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對武林網網站的支持!
新聞熱點
疑難解答