Vuetify / Vue-CLI问题编译;收到换行错误

时间:2019-10-13 19:10:52

标签: vue.js vuetify.js vue-cli-3 sass-loader

过去几个小时,我一直在互联网上寻找答案。我要疯了。

我有一个新的Vue项目,我从vue-cli开始,并添加了Vuetify。运行yarn serve时,出现一百个错误,抱怨:

 ERROR  Failed to compile with 100 errors                                                                   2:02:26 PM

 error  in ./node_modules/vuetify/src/components/VColorPicker/VColorPickerSwatches.sass

Module build failed (from ./node_modules/sass-loader/lib/loader.js):


                                                                                                                                         ^
      Expected newline.
  ╷
6 │ var content = require("!!../../../../css-loader/dist/cjs.js!../../../../sass-loader/lib/loader.js??ref--14-2!./VColorPickerSwatches.sass");
  │                                                                                                                                           ^
  ╵
  stdin 6:139  root stylesheet
      in /Users/jimmiejackson/Documents/repositories/gear_closet/frontend/node_modules/vuetify/src/components/VColorPicker/VColorPickerSwatches.sass (line 6, column 139)

 @ ./node_modules/vuetify/src/components/VColorPicker/VColorPickerSwatches.sass 4:14-343 14:3-18:5 15:22-351
 @ ./node_modules/vuetify/lib/components/VColorPicker/VColorPickerSwatches.js
 @ ./node_modules/vuetify/lib/components/VColorPicker/VColorPicker.js
 @ ./node_modules/vuetify/lib/components/VColorPicker/index.js
 @ ./node_modules/vuetify/lib/components/index.js
 @ ./node_modules/vuetify/lib/index.js
 @ ./src/plugins/vuetify.js
 @ ./src/main.js
 @ multi (webpack)-dev-server/client?http://192.168.1.84:8080/sockjs-node (webpack)/hot/dev-server.js ./src/main.js

我尝试了升级/降级sass-loader,删除node-sass和各种Webpack配置(通过vue.config.js)。有人有解决方案吗?

main.js

import Vue from 'vue';
import vueHeadful from 'vue-headful';
import vuetify from './plugins/vuetify';

import App from './App.vue';
import router from './router';
import store from './store/index';

Vue.config.productionTip = false;

Vue.component('vue-headful', vueHeadful);

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

vuetify.js

import Vue from 'vue';
import Vuetify from 'vuetify/lib';
import Unicon from 'vue-unicons';
import { uniCarWash } from 'vue-unicons/src/icons';

Vue.use(Vuetify);

Unicon.add([uniCarWash]);
Vue.use(Unicon);

export default new Vuetify({
  icons: {
    iconfont: 'uni',
  },
});

vue.config.js

const path = require('path');

module.exports = {
  transpileDependencies: [
    'vuetify',
  ],
  css: {
    loaderOptions: {
      sass: {
        data: `@import "~/scss/variables.scss"`,
      },
    },
  },
  chainWebpack: config => {
    ["vue-modules", "vue", "normal-modules", "normal"].forEach(match => {
      config.module.rule('scss').oneOf(match).use('sass-loader')
        .tap(opt => Object.assign(opt, { data: `@import '~@/scss/variables.scss';` }));
    });
  },
  configureWebpack: {
    resolve: {
      alias: {
        '~': path.resolve(__dirname, './src/'),
      },
      extensions: ['*', '.js', '.vue', '.json'],
    },
    module: {
      rules: [
        {
          test: /\.s(c|a)ss$/,
          use: [
            'vue-style-loader',
            'css-loader',
            {
              loader: 'sass-loader',
              options: {
                implementation: require('sass'),
                fiber: require('fibers'),
              },
            },
          ],
        },
      ],
    },
  },
};

package.json

{
  "name": "newapp",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "serve": "vue-cli-service serve",
    "build": "vue-cli-service build",
    "lint": "vue-cli-service lint"
  },
  "dependencies": {
    "axios": "^0.19.0",
    "core-js": "^2.6.5",
    "css-loader": "^3.2.0",
    "style-loader": "^1.0.0",
    "vee-validate": "^3.0.11",
    "vue": "^2.6.10",
    "vue-headful": "^2.0.1",
    "vue-loader": "^15.7.1",
    "vue-router": "^3.0.3",
    "vuetify": "^2.1.0",
    "vuex": "^3.0.1"
  },
  "devDependencies": {
    "@vue/cli-plugin-babel": "^3.12.0",
    "@vue/cli-plugin-eslint": "^3.12.0",
    "@vue/cli-service": "^3.12.0",
    "@vue/eslint-config-airbnb": "^4.0.0",
    "babel-eslint": "^10.0.1",
    "deepmerge": "^4.1.1",
    "eslint": "^5.16.0",
    "eslint-import-resolver-webpack": "^0.11.1",
    "eslint-plugin-vue": "^5.0.0",
    "fibers": "^4.0.1",
    "path": "^0.12.7",
    "sass": "^1.17.4",
    "sass-loader": "7.1.0",
    "vue-cli-plugin-vuetify": "^1.0.1",
    "vue-template-compiler": "^2.6.10",
    "vuetify-loader": "^1.2.2"
  }
}

1 个答案:

答案 0 :(得分:1)

Vue CLI对sass-loader有自己的配置(并且已经在做您配置的事情),因此您为sass-loader添加的规则是添加一个重复的处理器,其中输出Vue CLI的sass-loader被输入到您的Vue CLI中,从而导致错误。解决方案是删除module.rules的配置。

请注意,您还要在resolve.extensions中复制Vue CLI配置。我建议使用vue inspect查看项目的已解析Webpack配置以进行故障排除。在进行更改之前和之后对输出进行比较很有帮助。