解決Vue中"This dependency was not found"的方法


今天在初始化項目中,出現了一個奇怪的情況:明明路徑是對的,但是編譯的時候,一直報“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)
})


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM