解决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)
})

更多专业前端知识,请上 【猿2048】www.mk2048.com
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值