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

Vuetify/Vue-CLI issues compiling; receiving newline error

过去几个小时我一直在网上搜索答案。我快要疯了。

我有一个新的 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

我已经尝试 upgrading/downgrading 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"
  }
}

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

的配置

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