【问题标题】:Getting error message Module build failed (from ./node_modules/sass-loader/dist/cjs.js) when running npm serve运行 npm serve 时收到错误消息模块构建失败(来自 ./node_modules/sass-loader/dist/cjs.js)
【发布时间】:2020-01-12 13:52:39
【问题描述】:

我从事 Vue/Vuetify 项目已经有一段时间了。直到昨天一切都很好。我在使用 <v-simple-table> vuetify 组件时遇到问题,所以我决定运行 npm install 并重新安装 vuetify:坏主意。

问题是我在运行npm run serve时多次收到以下错误:

Module build failed (from ./node_modules/sass-loader/dist/cjs.js):
ValidationError: Invalid options object. Sass Loader has been initialised using an options object that does not match the API schema.
 - options has an unknown property 'indentedSyntax'. These properties are valid:
   object { implementation?, sassOptions?, prependData?, sourceMap?, webpackImporter? }
    at validate (C:\Users\Jeroen\Documents\favourite_xi\node_modules\sass-loader\node_modules\schema-utils\dist\validate.js:49:11)
    at Object.loader (C:\Users\Jeroen\Documents\favourite_xi\node_modules\sass-loader\dist\index.js:36:28)

 @ ./node_modules/vuetify/src/components/VCalendar/mixins/calendar-with-events.sass 4:14-225 14:3-18:5 15:22-233
 @ ./node_modules/vuetify/lib/components/VCalendar/mixins/calendar-with-events.js
 @ ./node_modules/vuetify/lib/components/VCalendar/VCalendar.js
 @ ./node_modules/vuetify/lib/components/VCalendar/index.js
 @ ./node_modules/vuetify/lib/components/index.js
 @ ./node_modules/vuetify/lib/index.js
 @ ./src/main.js
 @ multi (webpack)-dev-server/client?http://192.168.178.115:8080/sockjs-node ./node_modules/@vue/cli-service/node_modules/webpack/hot/dev-server.js ./src/main.js

我的 main.js 文件:

import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'

import Vuetify from 'vuetify/lib'
import 'vuetify/dist/vuetify.min.css'
import 'bootstrap/dist/css/bootstrap.css'
import 'bootstrap-vue/dist/bootstrap-vue.css'

Vue.use(BootstrapVue)
Vue.use(Vuetify, {
  theme: {
    "primary": "#FFCA28",
    "secondary": "#1976D2",
    "accent": "#82B1FF",
    "error": "#FF5252",
    "info": "#2196F3",
    "success": "#4CAF50",
    "warning": "#FB8C00"
  }
})

Vue.config.productionTip = false

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')

我已经看过多个帖子,他们都建议运行npm rebuild node-sass(都在管理员模式下定期运行),删除 node-modules 文件夹,重新安装 sass-loader,但到目前为止没有任何效果。

我的 main.js 可能有问题吗?

提前致谢!如果我需要发布更多代码或其他信息,请告诉我。

编辑:添加 package.json

{
  "name": "favourite_xi",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "serve": "vue-cli-service serve",
    "build": "vue-cli-service build",
    "lint": "vue-cli-service lint"
  },
  "dependencies": {
    "bootstrap": "^4.3.1",
    "bootstrap-vue": "^2.0.0-rc.22",
    "core-js": "^2.6.5",
    "node-sass": "^4.12.0",
    "stylus": "^0.54.7",
    "stylus-loader": "^3.0.2",
    "uuid": "^3.3.3",
    "vue": "^2.6.10",
    "vue-cool-select": "^2.10.2",
    "vue-flip": "^0.3.0",
    "vue-responsive-text": "^0.1.4",
    "vue-router": "^3.0.3",
    "vuetify": "^2.0.16",
    "vuex": "^3.1.1"
  },
  "devDependencies": {
    "@fortawesome/fontawesome-free": "^5.10.1",
    "@vue/cli-plugin-babel": "^3.8.0",
    "@vue/cli-plugin-eslint": "^3.8.0",
    "@vue/cli-service": "^3.8.0",
    "@vue/eslint-config-standard": "^4.0.0",
    "babel-eslint": "^10.0.1",
    "eslint": "^5.16.0",
    "eslint-plugin-vue": "^5.0.0",
    "sass-loader": "^8.0.0",
    "vue-template-compiler": "^2.6.10",
    "webpack": "^4.39.3"
  },
  "eslintConfig": {
    "root": true,
    "env": {
      "node": true
    },
    "extends": [
      "plugin:vue/essential",
      "@vue/standard"
    ],
    "rules": {},
    "parserOptions": {
      "parser": "babel-eslint"
    }
  },
  "postcss": {
    "plugins": {
      "autoprefixer": {}
    }
  },
  "browserslist": [
    "> 1%",
    "last 2 versions"
  ]
}

【问题讨论】:

  • 你也可以显示 package.json 吗?
  • 完成,感谢观看!
  • 那么,你npm install在删除node_modules之后运行了吗?
  • 您是否更新了 package.json 中的任何内容?似乎您的节点模块之间不兼容。见这里:github.com/vuejs/vue-cli/issues/4513 更新vue-cli 应该可以解决它。
  • 感谢您的回复。更新 vue-cli 没有帮助。 npm install 确实在删除我的节点模块后运行,但也没有运气

标签: javascript vue.js vuetify.js sass-loader


【解决方案1】:

这可能是 sass-loader 从 v7.x 升级到 v8.x 的结果

正如release notes 中所述,他们对配置进行了重大更改

检查你的vue.config.js - 如果你发现这样的东西:

module.exports = {
  css: {
    loaderOptions: {
      sass: {
        ....some options here...
      }
    }
  }
}

改成:

module.exports = {
  css: {
    loaderOptions: {
      sass: {
        sassOptions: {
          ....some options here...
        }
      }
    }
  }
}

【讨论】:

    【解决方案2】:

    我不确定它是否有用,但我的npm run build 主题颜色代码错误。当我注释掉它构建的颜色代码行时没有错误:

        Vue.use(Vuetify, {
          theme: {
            "primary": "#FFCA28",
            "secondary": "#1976D2",
            "accent": "#82B1FF",
            "error": "#FF5252",
            "info": "#2196F3",
            "success": "#4CAF50",
            "warning": "#FB8C00"
          }
        })
    

    【讨论】:

      猜你喜欢
      • 2020-08-14
      • 2021-10-31
      • 2020-07-03
      • 2021-03-05
      • 2022-10-22
      • 2023-02-20
      • 2020-09-01
      • 2022-12-13
      • 1970-01-01
      相关资源
      最近更新 更多