欢迎来到 跌倒的小黄瓜 的博客

♪(^∇^*)我要当大佬,(#^.^#)哈哈哈哈,(。-ω-)zzz我要成为优秀的人,(*^▽^*)٩(๑>◡<๑)۶O(∩_∩)O哈哈~~~~~~~~欢迎━(*`∀´*)ノ亻!

解决vue-cli使用组件报错

今天使用vue-cli,明明写的没错,都是vue-cli自动生成的,编译时怎嘛就会报错呢?

报错信息如下:

浏览器端报错:

Failed to compile. ./src/components/Hi1.vue Module not found: 
Error: Can't resolve 'stylus-loader' in 'E:\desktop\vue-review\vuejs\vue-cli\vuecli\src\components' @ ./src/components/Hi1.vue 4:2-310 @ ./src/router/index.js @ ./src/main.js @ multi (webpack)-dev-server/client?http://localhost:8080 webpack/hot/dev-server ./src/main.js

控制台报错:

These dependencies were not found:

* !!vue-style-loader!css-loader?{"sourceMap":true}!../../node_modules/vue-loader/lib/style-compiler/index?{"vue":true,"id":"data-v-3232a8d1","scoped":true,"hasInlineConfig":false}!stylus-loader?{"sourceMap":true}!../../node_modules/vue-loader/lib/selector?type=styles&index=0!./Hi2.vue in ./src/components/Hi2.vue
* !!vue-style-loader!css-loader?{"sourceMap":true}!../../node_modules/vue-loader/lib/style-compiler/index?{"vue":true,"id":"data-v-32249150","scoped":true,"hasInlineConfig":false}!stylus-loader?{"sourceMap":true}!../../node_modules/vue-loader/lib/selector?type=styles&index=0!./Hi1.vue in ./src/components/Hi1.vue

To install them, you can run: npm install --save !!vue-style-loader!css-loader?{"sourceMap":true}!../../node_modules/vue-loader/lib/style-compiler/index?{"vue":true,"id":"data-v-3232a8d1","scoped":true,"hasInlineConfig":false}!stylus-loader?{"sourceMap":true}!../../node_modules/vue-loader/lib/selector?type=styles&index=0!./Hi2.vue !!vue-style-loader!css-loader?{"sourceMap":true}!../../node_modules/vue-loader/lib/style-compiler/index?{"vue":true,"id":"data-v-32249150","scoped":true,"hasInlineConfig":false}!stylus-loader?{"sourceMap":true}!../../node_modules/vue-loader/lib/selector?type=styles&index=0!./Hi1.vue

原来vue-cli在初始化项目时在package.json中没有引入 stylus和stylus-loader,而我在写代码时有用vscode的自动提示功能,然后就导致了错误的代码出现,(其实也不算错误,但我还是这么叫它)

<style lang="stylus" scoped>

</style>

就因为代码提示自动生成的lang="stylus",巧了,vue-cli初始化就没这方面的包

只要在项目根目录下运行:npm install stylus stylus-loader --save-dev,在停止vue-cli,重新npm run dev一下就ok了(如果过改了package.json里的dev,可能不是这个命令运行vue-cli

有时候太图方便也不好,尤其是在不了解它时o(╥﹏╥)o

posted @ 2020-02-06 20:16  跌倒的小黄瓜  阅读(...)  评论(...编辑  收藏