CSS Loader has been initialised using an options object that does not match the API schema
Asked Answered
T

4

18

Production build fails with the following error:

ValidationError: Invalid options object. CSS Loader has been initialised using an options object that does not match the API schema.
 - options has an unknown property 'minimize'. These properties are valid:
   object { url?, import?, modules?, sourceMap?, importLoaders?, localsConvention?, onlyLocals? }
    at validate (/Users/username/Sites/projectname/node_modules/css-loader/node_modules/schema-utils/dist/validate.js:85:11)
    at Object.loader (/Users/username/Sites/projectname/node_modules/css-loader/dist/index.js:34:28)

Using this webpack template: http://vuejs-templates.github.io/webpack/, updated to Webpack 4 and faced build issues, package.json:

{
  "name": "projectname",
  "private": true,
  "scripts": {
    "dev": "webpack-dev-server --inline --progress --config webpack.config.js --port 3000 --hot",
    "start": "npm run dev",
    "build": "cross-env NODE_ENV=production webpack --progress --hide-modules"
  },
  "dependencies": {
    "@vue/cli-service": "^3.2.0",
    "axios": "^0.18.0",
    "babel-polyfill": "^6.26.0",
    "cross-env": "^5.2.0",
    "css-loader": "^3.2.1",
    "jquery": "^3.3.1",
    "moment": "^2.22.2",
    "style-loader": "^1.0.1",
    "swiper": "^4.5.0",
    "v-tabs-router": "^1.4.0",
    "vee-validate": "^2.1.0-beta.9",
    "vue": "^2.5.2",
    "vue-awesome-swiper": "^3.1.3",
    "vue-backtotop": "^1.6.1",
    "vue-carousel": "^0.18.0",
    "vue-cleave-component": "^2.1.2",
    "vue-instant": "^1.0.2",
    "vue-jsonp": "^0.1.8",
    "vue-magic-line": "^0.2.1",
    "vue-masked-input": "^0.5.2",
    "vue-resource": "^1.5.1",
    "vue-router": "^3.0.2",
    "vue-select": "^2.5.1",
    "vue-slider-component": "^2.8.0",
    "vue-smooth-scroll": "^1.0.13",
    "vuejs-datepicker": "^1.5.3",
    "vuelidate": "^0.7.4",
    "vuex": "^3.0.1"
  },
  "devDependencies": {
    "autoprefixer": "^7.1.2",
    "babel-core": "^6.22.1",
    "babel-helper-vue-jsx-merge-props": "^2.0.3",
    "babel-loader": "^7.1.1",
    "babel-plugin-syntax-jsx": "^6.18.0",
    "babel-plugin-transform-runtime": "^6.22.0",
    "babel-plugin-transform-vue-jsx": "^3.5.0",
    "babel-preset-env": "^1.3.2",
    "babel-preset-stage-2": "^6.22.0",
    "chalk": "^2.0.1",
    "copy-webpack-plugin": "^4.0.1",
    "extract-text-webpack-plugin": "^3.0.0",
    "file-loader": "^5.0.2",
    "friendly-errors-webpack-plugin": "^1.6.1",
    "html-webpack-plugin": "^3.2.0",
    "node-notifier": "^5.1.2",
    "node-sass": "^4.13.0",
    "optimize-css-assets-webpack-plugin": "^5.0.3",
    "ora": "^1.2.0",
    "portfinder": "^1.0.13",
    "postcss-import": "^12.0.1",
    "postcss-loader": "^3.0.0",
    "postcss-url": "^8.0.0",
    "rimraf": "^2.6.0",
    "sass-loader": "^8.0.0",
    "semver": "^5.3.0",
    "shelljs": "^0.7.6",
    "uglifyjs-webpack-plugin": "^1.1.1",
    "url-loader": "^1.1.2",
    "vue-loader": "^14.2.2",
    "vue-resource": "^1.5.1",
    "vue-style-loader": "^4.1.2",
    "vue-template-compiler": "^2.5.2",
    "webpack": "^4.41.2",
    "webpack-cli": "^3.3.10",
    "webpack-dev-server": "^3.9.0"
  },
  "engines": {
    "node": ">= 6.0.0",
    "npm": ">= 3.0.0"
  },
  "browserslist": [
    "> 1%",
    "last 2 versions",
    "not ie <= 8"
  ]
}

I've checked with grep -rl 'minimize' . in a project root, but didn't found any related options. Wth..

Tangram answered 8/12, 2019 at 11:40 Comment(2)
Facing the same issue after upgradingTherapeutic
did you fix this problem? what did you do to make it work? @Alexander KimApotheosize
W
25

This has to do with a breaking change in the module. According to semver rules, a major change (first digit x of version x.y.z) is a breaking change.

In this case the old version syntax uses

    {
        loader: 'postcss-loader',
        options: {
            plugins: postCSSPlugins
        }
    }

whereas the new version in options uses nested postcssOptions before plugins

    {
        loader: 'postcss-loader',
        options: {
            postcssOptions: {
                plugins: postCSSPlugins
            }
        }
    }
Walsh answered 31/10, 2020 at 10:21 Comment(2)
what is postCSSPlugins define? @WalshApotheosize
it is constant defined by user for plugins to group together. sorry i forgot write about this . const postCSSPlugins = [ require('postcss-import'), require('postcss-mixins'), require('postcss-simple-vars'), require('postcss-nested'), require('postcss-hexrgba'), require('autoprefixer') ]Walsh
E
8

I also encountered this error when updating to webpack 4 and using MiniCssExtractPlugin

I was able to eliminate the error and get a successful build by using an older version of ccs-loader

These versions worked for me

 "devDependencies": {
   "css-loader": "1.0.1",

OR

   "css-loader": "^0.28.0",

css-loader 2* and 3* gave me the error.

UPDATE after testing publish: using the old version of the css-loader causes the css to fail to load when rendering the web site in a browser. So this appears to not be a solution.

Eastsoutheast answered 2/2, 2020 at 2:5 Comment(0)
T
2

I was having the same issue after I ran yarn upgrade --latest command.

It changed sass-loader version from 7.1.0 to 8.0.0. After that getting the same error.

There might be change in sass-loader options and due to that, this error occurred. You can check release: https://github.com/webpack-contrib/sass-loader/releases and updated options https://github.com/webpack-contrib/sass-loader

Try to remove/change sass-loader options, that can help you to resolve it.

Hope this can help, it would be great if can you share webpack.config.js file.

Cheers~

Therapeutic answered 3/1, 2020 at 11:48 Comment(1)
I check my config and did not found any option config but still facing the problem.@Ajay Patel #70775240Apotheosize
E
1

I had a similar problem upgrading to webpack 4. I used Vue.js CLI which generated a build/utils.js file that effectively has a configurable webpack based on whether I am in a development or a production environment.

Pertinent utils.js lines in auto generated (failing after upgrading) code:

var ExtractTextPlugin = require('extract-text-webpack-plugin')

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

  var cssLoader = {
    loader: 'css-loader',
    options: {
      minimize: process.env.NODE_ENV === 'production',
      sourceMap: options.sourceMap
    }
  }

  // generate loader string to be used with extract text plugin
  function generateLoaders (loader, loaderOptions) {
    var loaders = [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.loader({
        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')
  }
}

I tried the simple, "Let's just update the module.":

var ExtractTextPlugin = require('mini-css-extract-plugin')

Which gave me the error that you had. After much messing around with the files, I used the "Easter Egg Troubleshooting Strategy", and found that I could do the following and get it to work. What worked was the following:

npm i extract-loader --save-dev

then modify build/utils.js:

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

  var cssLoader = {
    loader: 'css-loader',
    options: {
      // minimize: process.env.NODE_ENV === 'production',
      sourceMap: options.sourceMap
    }
  }

  // generate loader string to be used with extract text plugin
  function generateLoaders (loader, loaderOptions) {
    var loaders = [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 ['extract-loader'].concat(loaders)
      // return ExtractTextPlugin.loader({
      //   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')
  }
}

Notice, I commented out line 9, which is the source of my error. I also removed my sole dependency to the mini-css-extract-plugin with the extract-loader module.

      // minimize: process.env.NODE_ENV === 'production',

Now I have to figure out why eslint is not liking my Vue syntax.

Echino answered 10/4, 2020 at 18:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.