• 解决vue-cli使用组件报错


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

    报错信息如下:

    浏览器端报错:

    Failed to compile. ./src/components/Hi1.vue Module not found: 
    Error: Can't resolve 'stylus-loader' in 'E:desktopvue-reviewvuejsvue-clivueclisrccomponents' @ ./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

  • 相关阅读:
    Oracle expdp impdp中 exclude/include 的使用
    Oracle表空间迁移Move Tablespace
    m2ewtp的作用
    有意思的排序算法合并排序
    有意思的排序算法插入排序
    equals与“==”之惑
    简化的打印语句静态导入
    有意思的排序算法堆排序
    博客开篇语
    MySQL 整理笔记 张大哥
  • 原文地址:https://www.cnblogs.com/ygjzs/p/12270171.html
Copyright © 2020-2023  润新知