Webpack: Module build failed: Invalid CSS after "...load the styles": expected 1 selector or at-rule, was "var content = requi"

Created on 29 Jul 2018  ·  4Comments  ·  Source: vuejs-templates/webpack

Expected behavior

in the main.js I import my scss file
import './assets/scss/style.scss';
And it should compile to CSS and be used.

Actuall behavior

Compile fails with one error

 error  in ./src/assets/scss/style.scss

Module build failed: 
nav{
^
      Invalid CSS after "...load the styles": expected 1 selector or at-rule, was "var content = requi"
      in /path/src/assets/scss/style.scss (line 1, column 1)

 @ ./src/assets/scss/style.scss 2:14-360 21:1-42:3 22:19-365
 @ ./src/main.js
 @ multi (webpack)-dev-server/client?http://localhost:8080 webpack/hot/dev-server ./src/main.js

More info about the issue

In my webpack.base.conf.js file

const ExtractTextPlugin = require('extract-text-webpack-plugin');
rules: [
    {
        test: /\.scss$/,
        use: ExtractTextPlugin.extract({
            fallback: 'style-loader',
            use: ['css-loader', 'sass-loader']
        })
    },
]
plugins: [
    new ExtractTextPlugin('style.scss')
],

utils.js file

'use strict'
const path = require('path')
const config = require('../config')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const packageConfig = require('../package.json')

exports.assetsPath = function (_path) {
  const assetsSubDirectory = process.env.NODE_ENV === 'production'
    ? config.build.assetsSubDirectory
    : config.dev.assetsSubDirectory

  return path.posix.join(assetsSubDirectory, _path)
}

exports.cssLoaders = function (options) {
  options = options || {}

  const cssLoader = {
    loader: 'css-loader',
    options: {
      sourceMap: options.sourceMap
    }
  }

  const postcssLoader = {
    loader: 'postcss-loader',
    options: {
      sourceMap: options.sourceMap
    }
  }

  // generate loader string to be used with extract text plugin
  function generateLoaders (loader, loaderOptions) {
    const loaders = options.usePostCSS ? [cssLoader, postcssLoader] : [cssLoader]

    if (loader) {
      loaders.push({
        loader: loader + '-loader',
        options: Object.assign({}, loaderOptions, {
          sourceMap: options.sourceMap
        })
      })
    }

    // Extract CSS when that option is specified
    // (which is the case during production build)
    if (options.extract) {
      return ExtractTextPlugin.extract({
        use: loaders,
        fallback: 'vue-style-loader'
      })
    } else {
      return ['vue-style-loader'].concat(loaders)
    }
  }

  // https://vue-loader.vuejs.org/en/configurations/extract-css.html
  return {
    css: generateLoaders(),
    postcss: generateLoaders(),
    less: generateLoaders('less'),
    sass: generateLoaders('sass', { indentedSyntax: true }),
    scss: generateLoaders('sass'),
    stylus: generateLoaders('stylus'),
    styl: generateLoaders('stylus')
  }
}

// Generate loaders for standalone style files (outside of .vue)
exports.styleLoaders = function (options) {
  const output = []
  const loaders = exports.cssLoaders(options)

  for (const extension in loaders) {
    const loader = loaders[extension]
    output.push({
      test: new RegExp('\\.' + extension + '$'),
      use: loader
    })
  }

  return output
}

exports.createNotifierCallback = () => {
  const notifier = require('node-notifier')

  return (severity, errors) => {
    if (severity !== 'error') return

    const error = errors[0]
    const filename = error.file && error.file.split('!').pop()

    notifier.notify({
      title: packageConfig.name,
      message: severity + ': ' + error.name,
      subtitle: filename || '',
      icon: path.join(__dirname, 'logo.png')
    })
  }
}

All 4 comments

I have fixed the problem.

I updated to the new Vue cli 3.0 and started from scratch with my project.

你把你的配置sass那段删掉就好了

So how to fix this, I just installed builerplate added scss rule and get the same error.

I managed to fix it by importing the styles.scss in my App.vue file:

Was this page helpful?
0 / 5 - 0 ratings