Vue中Thisdependencywasnotfound问题的解决⽅法今天在初始化项⽬中,出现了⼀个奇怪的情况:明明路径是对的,但是编译的时候,⼀直报“This dependency was not found”的错。
代码如下:
editor记忆方法
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"的问题的解决⽅法,希望对⼤家有所帮助,如果⼤家有任何疑问请给我留⾔,⼩编会及时回复⼤家的。在此也⾮常感谢⼤家对⽹站的⽀持!