Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vue-cli and sass-loader@8 incompatibility #4513

Closed
jacekkarczmarczyk opened this issue Aug 29, 2019 · 37 comments
Closed

vue-cli and sass-loader@8 incompatibility #4513

jacekkarczmarczyk opened this issue Aug 29, 2019 · 37 comments

Comments

@jacekkarczmarczyk
Copy link

jacekkarczmarczyk commented Aug 29, 2019

Version

4.0.0-rc.0

Reproduction link

https://github.com/jacekkarczmarczyk/vue-cli-sass-loader-repro

Environment info

  System:
    OS: Windows 10
    CPU: (8) x64 Intel(R) Core(TM) i7-4700HQ CPU @ 2.40GHz
  Binaries:
    Node: 12.6.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.17.3 - C:\Users\Jacek\AppData\Roaming\npm\yarn.CMD
    npm: 6.10.0 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: 42.17134.1.0
  npmPackages:
    @vue/babel-helper-vue-jsx-merge-props:  1.0.0
    @vue/babel-plugin-transform-vue-jsx:  1.0.0
    @vue/babel-preset-app:  3.11.0
    @vue/babel-preset-jsx:  1.1.0
    @vue/babel-sugar-functional-vue:  1.0.0
    @vue/babel-sugar-inject-h:  1.0.0
    @vue/babel-sugar-v-model:  1.0.0
    @vue/babel-sugar-v-on:  1.1.0
    @vue/cli-overlay:  3.11.0
    @vue/cli-plugin-babel: ^3.2.0 => 3.11.0
    @vue/cli-plugin-eslint: ^3.2.0 => 3.11.0
    @vue/cli-plugin-typescript: ^3.2.0 => 3.11.0
    @vue/cli-service: ^3.2.0 => 3.11.0
    @vue/cli-shared-utils:  3.11.0
    @vue/component-compiler-utils:  3.0.0
    @vue/eslint-config-standard: ^4.0.0 => 4.0.0
    @vue/eslint-config-typescript: ^4.0.0 => 4.0.0
    @vue/preload-webpack-plugin:  1.1.1
    @vue/test-utils: ^1.0.0-beta.20 => 1.0.0-beta.29
    @vue/web-component-wrapper:  1.2.0
    eslint-plugin-vue: ^5.0.0 => 5.2.3 (4.7.1)
    eslint-plugin-vuetify: ^1.0.0-beta.1 => 1.0.0-beta.3
    typescript: ~3.5.0 => 3.5.3
    vue: ^2.5.21 => 2.6.10
    vue-eslint-parser:  5.0.0 (2.0.3)
    vue-hot-reload-api:  2.3.3
    vue-loader:  15.7.1
    vue-style-loader:  4.1.2
    vue-template-compiler: ^2.5.21 => 2.6.10
    vue-template-es2015-compiler:  1.9.1
  npmGlobalPackages:
    @vue/cli: Not Found

Steps to reproduce

Clone the repo and run yarn && yarn build

What is expected?

Successfull build

What is actually happening?

$ vue-cli-service build

-  Building for production...
Starting type checking service...
Using 1 worker with 2048MB memory limit
 ERROR  Failed to compile with 1 errors22:27:09

 error  in ./src/App.vue?vue&type=style&index=0&lang=sass&

Module build failed (from ./node_modules/mini-css-extract-plugin/dist/loader.js):
ModuleBuildError: 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:\cygwin64\home\Jacek\karpc\repro\node_modules\sass-loader\node_modules\schema-utils\dist\validate.js:49:11)
    at Object.loader (C:\cygwin64\home\Jacek\karpc\repro\node_modules\sass-loader\dist\index.js:36:28)
    at C:\cygwin64\home\Jacek\karpc\repro\node_modules\webpack\lib\NormalModule.js:313:20
    at C:\cygwin64\home\Jacek\karpc\repro\node_modules\loader-runner\lib\LoaderRunner.js:367:11
    at C:\cygwin64\home\Jacek\karpc\repro\node_modules\loader-runner\lib\LoaderRunner.js:233:18
    at runSyncOrAsync (C:\cygwin64\home\Jacek\karpc\repro\node_modules\loader-runner\lib\LoaderRunner.js:143:3)
    at iterateNormalLoaders (C:\cygwin64\home\Jacek\karpc\repro\node_modules\loader-runner\lib\LoaderRunner.js:232:2)
    at iterateNormalLoaders (C:\cygwin64\home\Jacek\karpc\repro\node_modules\loader-runner\lib\LoaderRunner.js:221:10)
    at C:\cygwin64\home\Jacek\karpc\repro\node_modules\loader-runner\lib\LoaderRunner.js:236:3
    at context.callback (C:\cygwin64\home\Jacek\karpc\repro\node_modules\loader-runner\lib\LoaderRunner.js:111:13)
    at C:\cygwin64\home\Jacek\karpc\repro\node_modules\cache-loader\dist\index.js:118:7
    at C:\cygwin64\home\Jacek\karpc\repro\node_modules\graceful-fs\graceful-fs.js:57:14
    at FSReqCallback.oncomplete (fs.js:153:23)

 @ ./src/App.vue?vue&type=style&index=0&lang=sass& 1:0-480 1:496-499 1:501-978 1:501-978
 @ ./src/App.vue
 @ ./src/main.ts
 @ multi ./src/main.ts

Error goes off when you remove <style> section from App.vue

It also worked when I removed

defaultSassLoaderOptions.fiber = require('fibers')

in https://github.com/vuejs/vue-cli/blob/dev/packages/%40vue/cli-service/lib/config/css.js#L21 and changed

indentedSyntax: true

to

sassOptions: { 
  indentedSyntax: true 
}

in https://github.com/vuejs/vue-cli/blob/dev/packages/%40vue/cli-service/lib/config/css.js#L181

@bromix
Copy link

bromix commented Aug 30, 2019

Same problem here. My output of the log looks the same.

@LinusBorg
Copy link
Member

For the record, we install ^7.0.0 explicitly, so this won't affect users unless they actively choose to do a major version bump of this dependency.

@jacekkarczmarczyk
Copy link
Author

You're absolutely right, but maybe it's worth to make 4.0 compatible with new sass loader? Since the stable version is not released yet, so it's the last moment to update it as I guess otherwise we will have to wait for vue-cli 5?
Of course this seems to be breaking change which you may not want to add since the RC version is already released

@SavkaTaras
Copy link

I had issue with 'data' in sassLoader. Apparently they renamed it to 'prependData' and did some changes, so you would have to look into their documentation or read the output. I use Node, not Yarn.

@jacquesmatthieu
Copy link

I've got the same problem what's the solution ? I can't build Vuetify module in my project ...

 error  in ./packages/app/node_modules/vuetify/src/components/VSubheader/VSubheader.sass

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 (myproject/node_modules/sass-loader/node_modules/schema-utils/dist/validate.js:49:11)
    at Object.loader (myproject/node_modules/sass-loader/dist/index.js:36:28)

 @ ./packages/app/node_modules/vuetify/src/components/VSubheader/VSubheader.sass 4:14-272 14:3-18:5 15:22-280
 @ ./packages/app/node_modules/vuetify/lib/components/VSubheader/VSubheader.js
 @ ./packages/app/node_modules/vuetify/lib/components/VSubheader/index.js
 @ ./packages/app/node_modules/vuetify/lib/components/VSelect/VSelectList.js
 @ ./packages/app/node_modules/vuetify/lib/components/VSelect/VSelect.js
 @ ./packages/app/node_modules/vuetify/lib/components/VSelect/index.js
 @ ./packages/app/node_modules/vuetify/lib/components/index.js
 @ ./packages/app/node_modules/vuetify/lib/index.js
 @ ./packages/app/src/main.js
 @ multi (webpack)-dev-server/client?http://172.20.10.2:8080/sockjs-node (webpack)/hot/dev-server.js ./packages/app/src/main.js

@SavkaTaras
Copy link

error in ./packages/app/node_modules/vuetify/src/components/VSubheader/VSubheader.sass

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 (myproject/node_modules/sass-loader/node_modules/schema-utils/dist/validate.js:49:11)
    at Object.loader (myproject/node_modules/sass-loader/dist/index.js:36:28)

@ ./packages/app/node_modules/vuetify/src/components/VSubheader/VSubheader.sass 4:14-272 14:3-18:5 15:22-280
@ ./packages/app/node_modules/vuetify/lib/components/VSubheader/VSubheader.js
@ ./packages/app/node_modules/vuetify/lib/components/VSubheader/index.js
@ ./packages/app/node_modules/vuetify/lib/components/VSelect/VSelectList.js
@ ./packages/app/node_modules/vuetify/lib/components/VSelect/VSelect.js
@ ./packages/app/node_modules/vuetify/lib/components/VSelect/index.js
@ ./packages/app/node_modules/vuetify/lib/components/index.js
@ ./packages/app/node_modules/vuetify/lib/index.js
@ ./packages/app/src/main.js
@ multi (webpack)-dev-server/client?http://172.20.10.2:8080/sockjs-node (webpack)/hot/dev-server.js ./packages/app/src/main.js

Would you mind sharing the project repo? I am interested what is happening there. Seems like 8.0.0 sass loader broke a lot of projects.

@LinusBorg
Copy link
Member

LinusBorg commented Aug 30, 2019

I've got the same problem what's the solution ? I can't build Vuetify module in my project ...

@jacquesmatthieu have you tried following the description in the OP? If you find problems along the way, ask more specifically.

Or simply use sass-loader v7, which is the version we installed for you initially, and which is the version we support right now.

@jacquesmatthieu
Copy link

@SavkaTaras I can't share the repo sorry. @LinusBorg I've got downgrade to sass-loader and it works. Thx you !

jyami-kim added a commit to professor-lol/professor-lol that referenced this issue Aug 31, 2019
vuetify 설치중 sassloader 문제 발생
vuejs/vue-cli#4513
2일전에 올라온 vue-cli와 sass-loader의 비호환성 문제인듯,
App.vue에 <style></style> 태그를 넣지 않으면 발생한다고하는데,
태그를 추가했으나 문제가 해결되지 않음

error log

 error  in ./node_modules/vuetify/src/components/VDataTable/VDataTable.sass

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\mor22\cleanCode\professor-lol\professorlol-web\src\front\node_modules\sass-loader\node_modules\schema-utils\dist\validate.js:49:11)
    at Object.loader (C:\Users\mor22\cleanCode\professor-lol\professorlol-web\src\front\node_modules\sass-loader\dist\index.js:36:28)
@ryanjwilke
Copy link

Having the same issue:

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 (/Users/ryanwilke/Sites/portfolio/node_modules/sass-loader/node_modules/schema-utils/dist/validate.js:49:11)
    at Object.loader (/Users/ryanwilke/Sites/portfolio/node_modules/sass-loader/dist/index.js:36:28)

 @ ./src/assets/styles/main.sass 4:14-233 14:3-18:5 15:22-241
 @ ./src/main.js
 @ multi (webpack)-dev-server/client?http://10.188.223.230:8080/sockjs-node (webpack)/hot/dev-server.js ./src/main.js

I upgraded to 4.0 cause I thought I read that would fix it, but apparently that's not the case.

@AlexLazareva
Copy link

AlexLazareva commented Sep 1, 2019

I have removed also row:

fiber: require('fibers'),

from file webpack.config.js in sass-loader
{ test: /\.s(c|a)ss$/, use: [ 'vue-style-loader', 'css-loader', { loader: 'sass-loader', options: { implementation: require('sass'), sassOptions: { indentedSyntax: true } } } ] }
And webpack started to work

@jacekkarczmarczyk
Copy link
Author

I guess this issue can be closed now since #4554 is now merged? @sodatea

@haoqunjiang
Copy link
Member

Yeah thanks for reminding

@haoqunjiang
Copy link
Member

haoqunjiang commented Sep 9, 2019

It's supported in 4.0.0-rc.3 and 3.12

@iagosilvamelo
Copy link

iagosilvamelo commented Oct 10, 2019

I solved creating the "webpack.config.js" .

module.exports = { module: { rules : [ { test: /\.vue$/, loader: 'vue-loader', options: { loaders: { scss: 'vue-style-loader!css-loader!sass-loader', sass: 'vue-style-loader!css-loader!sass-loader?indentedSyntax' }, preLoaders: { js: '/caminho/personalizado/para/carregador' }, postLoaders: { html: 'babel-loader' }, excludedPreLoaders: /(eslint-loader)/ } } ] } }

@TGRBTRFLY
Copy link

TGRBTRFLY commented Oct 12, 2019

Ok, wait, whaaat am I supposed to do if I have this error?

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 'data'. These properties are valid:
    object { implementation?, sassOptions?, prependData?, sourceMap?, webpackImporter? }
    at validate ...

@SavkaTaras
Copy link

Replace data with "prependData".

@Tzahile
Copy link
Contributor

Tzahile commented Oct 15, 2019

Replace data with "prependData".

In which file? webpack.config.js?

fix(webpack): correct sass options for sass-loader@8 #6460

But I thought it was merged?

@LinusBorg
Copy link
Member

They likely haven't upgraded to 3.12

@nstuyvesant
Copy link

nstuyvesant commented Oct 20, 2019

Replace data with "prependData".

In which file? webpack.config.js?

fix(webpack): correct sass options for sass-loader@8 #6460

But I thought it was merged?

In my case, I had to modify my export in vue.config.js (configureWebpack.css.loaderOptions.scss.data -> configureWebpack.css.loaderOptions.scss.prependData). Here's the complete file for context:

const PurgecssPlugin = require('purgecss-webpack-plugin');
const glob = require('glob-all');
const path = require('path');

module.exports = {
  assetsDir: 'src/assets',

  chainWebpack: config => {
    config.module
      .rule('vue')
      .use('vue-loader')
      .loader('vue-loader')
      .tap(options => {
        options['transformAssetUrls'] = {
          img: 'src',
          image: 'xlink:href',
          'b-carousel-slide': 'img-src',
          'b-embed': 'src'
        }

        return options
      })
  },

  configureWebpack: {
    plugins: [
      new PurgecssPlugin({
        paths: glob.sync([
          path.join(__dirname, './src/index.html'),
          path.join(__dirname, './**/*.vue'),
          path.join(__dirname, './src/**/*.js')
        ])
      })
    ]
  },

  css: {
    loaderOptions: {
      scss: {
        prependData: '@import "@/scss/variables.scss";'
      }
    }
  },

  pwa: {
    name: 'Acme',
    themeColor: '#5f4884',
    msTileColor: '#5f4884'
  }
};

@yankeeinlondon
Copy link

yankeeinlondon commented Nov 7, 2019

@nstuyvesant I have been having problems similar to others on this list and I too use Vuetify so I jumped at the chance to try your config. Sadly for me it fails with effectively no message or stack trace.

image

I presume the above config is working for you or have you made some adjustments since then? Also can you confirm that you're using Vuetify 2.x?

@nstuyvesant
Copy link

@ksnyde - in my case, I'm not using Vuetify - just bootstrap-vue. My config has not changed.

@johnsusek
Copy link

johnsusek commented Nov 9, 2019

I think the actual actionable issue here is that following these instructions:

https://cli.vuejs.org/guide/css.html#pre-processors

Causes 8.x to be installed.

Downgrading to 7.x works fine for me.

@danielbrigida
Copy link

@johnsusek Thank you, you solved my problem!

@geethikavinam
Copy link

Having the same issue:

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 (/Users/ryanwilke/Sites/portfolio/node_modules/sass-loader/node_modules/schema-utils/dist/validate.js:49:11)
    at Object.loader (/Users/ryanwilke/Sites/portfolio/node_modules/sass-loader/dist/index.js:36:28)

 @ ./src/assets/styles/main.sass 4:14-233 14:3-18:5 15:22-241
 @ ./src/main.js
 @ multi (webpack)-dev-server/client?http://10.188.223.230:8080/sockjs-node (webpack)/hot/dev-server.js ./src/main.js

I upgraded to 4.0 cause I thought I read that would fix it, but apparently that's not the case.

Hi , di d you fixed this?

@luxalpa
Copy link

luxalpa commented Nov 24, 2019

So, according to the migration guide, you're supposed to "take a look at the v8 release and upgrade to the latest version" but it's not actually supported... That's super odd.

@SoftwareDev1014
Copy link

I solved creating the "webpack.config.js" .

module.exports = { module: { rules : [ { test: /\.vue$/, loader: 'vue-loader', options: { loaders: { scss: 'vue-style-loader!css-loader!sass-loader', sass: 'vue-style-loader!css-loader!sass-loader?indentedSyntax' }, preLoaders: { js: '/caminho/personalizado/para/carregador' }, postLoaders: { html: 'babel-loader' }, excludedPreLoaders: /(eslint-loader)/ } } ] } }

It is working perfectly

@oivinds
Copy link

oivinds commented Feb 24, 2020

running vue serve after vue create fresh:

 ERROR  Failed to compile with 1 errors                                                                                  1:58:44 PM

 error  in ./src/App.vue?vue&type=style&index=0&lang=scss&

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

    color: #2c3e50;
                  ^
      Expected identifier.
   ╷
26 │     color: #2c3e50;
   │                    ^
   ╵
  stdin 26:20  root stylesheet
      in /Users/oiv/Desktop/fresh/src/App.vue (line 26, column 20)

 @ ./node_modules/vue-style-loader??ref--8-oneOf-1-0!./node_modules/css-loader/dist/cjs.js??ref--8-oneOf-1-1!./node_modules/vue-loa
der/lib/loaders/stylePostLoader.js!./node_modules/postcss-loader/src??ref--8-oneOf-1-2!./node_modules/sass-loader/dist/cjs.js??ref-
-8-oneOf-1-3!./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./src/App.vue?vue&type=style&index=0&lang=scss& 4:14-416 14:3-18:5 15:22-424
 @ ./src/App.vue?vue&type=style&index=0&lang=scss&
 @ ./src/App.vue
 @ ./src/main.ts
 @ multi (webpack)-dev-server/client?http://192.168.0.10:8080/sockjs-node (webpack)/hot/dev-server.js ./src/main.ts

Note: following suggestions for solutions in this repo, I also added fibers and downgraded sass-loader from 8 to 7. But the same build error persists.

package.json:

{
  "name": "fresh",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "serve": "vue-cli-service serve",
    "build": "vue-cli-service build"
  },
  "dependencies": {
    "core-js": "^3.6.4",
    "phaser": "3.22.0",
    "pug": "^2.0.4",
    "pug-plain-loader": "^1.0.0",
    "register-service-worker": "^1.6.2",
    "vue": "^2.6.11",
    "vue-class-component": "^7.2.2",
    "vue-property-decorator": "^8.3.0",
    "vue-router": "^3.1.5"
  },
  "devDependencies": {
    "@vue/cli-plugin-babel": "~4.2.0",
    "@vue/cli-plugin-pwa": "~4.2.0",
    "@vue/cli-plugin-router": "~4.2.0",
    "@vue/cli-plugin-typescript": "~4.2.0",
    "@vue/cli-service": "~4.2.0",
    "fibers": "^4.0.2",
    "sass": "^1.25.0",
    "sass-loader": "7.3.1",
    "typescript": "~3.7.5",
    "vue-template-compiler": "^2.6.11",
    "webpack": "^4.36.0"
  }
}

Environment Info:

  System:
    OS: macOS High Sierra 10.13.6
    CPU: (4) x64 Intel(R) Core(TM) i5-4288U CPU @ 2.60GHz
  Binaries:
    Node: 10.16.0 - /usr/local/bin/node
    Yarn: 1.22.0 - /usr/local/bin/yarn
    npm: 6.9.0 - /usr/local/bin/npm
  Browsers:
    Chrome: 79.0.3945.130
    Firefox: 73.0.1
    Safari: 13.0.5
  npmPackages:
    @vue/babel-helper-vue-jsx-merge-props:  1.0.0 
    @vue/babel-plugin-transform-vue-jsx:  1.1.2 
    @vue/babel-preset-app:  4.2.2 
    @vue/babel-preset-jsx:  1.1.2 
    @vue/babel-sugar-functional-vue:  1.1.2 
    @vue/babel-sugar-inject-h:  1.1.2 
    @vue/babel-sugar-v-model:  1.1.2 
    @vue/babel-sugar-v-on:  1.1.2 
    @vue/cli-overlay:  4.2.2 
    @vue/cli-plugin-babel: ~4.2.0 => 4.2.2 
    @vue/cli-plugin-pwa: ~4.2.0 => 4.2.2 
    @vue/cli-plugin-router: ~4.2.0 => 4.2.2 
    @vue/cli-plugin-typescript: ~4.2.0 => 4.2.2 
    @vue/cli-plugin-vuex:  4.2.2 
    @vue/cli-service: ~4.2.0 => 4.2.2 
    @vue/cli-shared-utils:  4.2.2 
    @vue/component-compiler-utils:  3.1.1 
    @vue/preload-webpack-plugin:  1.1.1 
    @vue/web-component-wrapper:  1.2.0 
    typescript: ~3.7.5 => 3.7.5 
    vue: ^2.6.11 => 2.6.11 
    vue-class-component: ^7.2.2 => 7.2.3 
    vue-hot-reload-api:  2.3.4 
    vue-loader:  15.9.0 
    vue-property-decorator: ^8.3.0 => 8.4.0 
    vue-router: ^3.1.5 => 3.1.5 
    vue-style-loader:  4.1.2 
    vue-template-compiler: ^2.6.11 => 2.6.11 
    vue-template-es2015-compiler:  1.9.1 
  npmGlobalPackages:
    @vue/cli: Not Found

@gustawdaniel
Copy link

@NaokiOtsu
Copy link

fixed by changing prependData -> additionalData

@balloonfight
Copy link

@NaokiOtsu Your post solved my problem! Very thanks!

@8bu
Copy link

8bu commented Aug 7, 2020

fixed by changing prependData -> additionalData

How come I got into the same error but I'm already using additionalData?
Just fixed by doing the opposite of that fix above...

@EmmyMay
Copy link

EmmyMay commented Aug 24, 2020

Replace data with "prependData".

In which file? webpack.config.js?

fix(webpack): correct sass options for sass-loader@8 #6460

But I thought it was merged?

In my case, I had to modify my export in vue.config.js (configureWebpack.css.loaderOptions.scss.data -> configureWebpack.css.loaderOptions.scss.prependData). Here's the complete file for context:

const PurgecssPlugin = require('purgecss-webpack-plugin');
const glob = require('glob-all');
const path = require('path');

module.exports = {
  assetsDir: 'src/assets',

  chainWebpack: config => {
    config.module
      .rule('vue')
      .use('vue-loader')
      .loader('vue-loader')
      .tap(options => {
        options['transformAssetUrls'] = {
          img: 'src',
          image: 'xlink:href',
          'b-carousel-slide': 'img-src',
          'b-embed': 'src'
        }

        return options
      })
  },

  configureWebpack: {
    plugins: [
      new PurgecssPlugin({
        paths: glob.sync([
          path.join(__dirname, './src/index.html'),
          path.join(__dirname, './**/*.vue'),
          path.join(__dirname, './src/**/*.js')
        ])
      })
    ]
  },

  css: {
    loaderOptions: {
      scss: {
        prependData: '@import "@/scss/variables.scss";'
      }
    }
  },

  pwa: {
    name: 'Acme',
    themeColor: '#5f4884',
    msTileColor: '#5f4884'
  }
};

Hi. This seems to work for me but I have multiple scss files. How would I import multiple scss files?

@EmmyMay
Copy link

EmmyMay commented Aug 24, 2020

Replace data with "prependData".

In which file? webpack.config.js?

fix(webpack): correct sass options for sass-loader@8 #6460

But I thought it was merged?

In my case, I had to modify my export in vue.config.js (configureWebpack.css.loaderOptions.scss.data -> configureWebpack.css.loaderOptions.scss.prependData). Here's the complete file for context:

const PurgecssPlugin = require('purgecss-webpack-plugin');
const glob = require('glob-all');
const path = require('path');

module.exports = {
  assetsDir: 'src/assets',

  chainWebpack: config => {
    config.module
      .rule('vue')
      .use('vue-loader')
      .loader('vue-loader')
      .tap(options => {
        options['transformAssetUrls'] = {
          img: 'src',
          image: 'xlink:href',
          'b-carousel-slide': 'img-src',
          'b-embed': 'src'
        }

        return options
      })
  },

  configureWebpack: {
    plugins: [
      new PurgecssPlugin({
        paths: glob.sync([
          path.join(__dirname, './src/index.html'),
          path.join(__dirname, './**/*.vue'),
          path.join(__dirname, './src/**/*.js')
        ])
      })
    ]
  },

  css: {
    loaderOptions: {
      scss: {
        prependData: '@import "@/scss/variables.scss";'
      }
    }
  },

  pwa: {
    name: 'Acme',
    themeColor: '#5f4884',
    msTileColor: '#5f4884'
  }
};

How would I import multiple scss files in the prependData? Thanks.

@EmmyMay
Copy link

EmmyMay commented Aug 24, 2020

The fix for this is to create a vue.config.js file or use the one already created if you can find it and then fill it with the below. Note that this fix is for folks using the vue cli

css: {
loaderOptions: {

   scss: {
 
     prependData: `@import "~@/scss/main.scss";`
   }
 }

}

in your main.scss, import all your mixins and variable files.

If you don't want to follow this approach, you could make prependData a function, loop through an array of all your '@import' statements and return each of the files out of the for loop block. Like below:

css: {
loaderOptions: {

   scss: {

     prependData: ()=>{
       var array = [`@import "~@/scss/main.scss";`, `@import "~@/scss/main.scss";`,
         `@import "~@/scss/main.scss";`,
         `@import "~@/scss/main.scss";`
       
       ]
       for (let index = 0; index < array.length; index++) {
         var element = array[index];
         
       }

       return element;
     }
   }
 }

}
you'll no longer need a single man.scss file

fredlawl added a commit to fredlawl/h4g-api-jobs that referenced this issue Nov 10, 2020
Sass loader on npm install automatically updates to latest version, and
there's a known issue at [1]. Fix this by downgrading sass-loader.

Links:
1. vuejs/vue-cli#4513
fredlawl added a commit to sgfdevs/h4g-api-jobs that referenced this issue Nov 10, 2020
Sass loader on npm install automatically updates to latest version, and
there's a known issue at [1]. Fix this by downgrading sass-loader.

Links:
1. vuejs/vue-cli#4513
@av1m
Copy link

av1m commented Apr 19, 2021

I do not know if it is this issue (it is the one that looks the most).

  1. I create a new project
vue create frontend

Vue CLI v4.5.12
? Please pick a preset: Manually select features
? Check the features needed for your project: Choose Vue version, Babel, TS, PWA
, Router, Vuex, CSS Pre-processors, Linter
? Choose a version of Vue.js that you want to start the project with 2.x
? Use class-style component syntax? Yes
? Use Babel alongside TypeScript (required for modern mode, auto-detected polyfi
lls, transpiling JSX)? Yes
? Use history mode for router? (Requires proper server setup for index fallback 
in production) Yes
? Pick a CSS pre-processor (PostCSS, Autoprefixer and CSS Modules are supported 
by default): Sass/SCSS (with dart-sass)
? Pick a linter / formatter config: Prettier
? Pick additional lint features: Lint on save
? Where do you prefer placing config for Babel, ESLint, etc.? In dedicated confi
g files
? Save this as a preset for future projects? No
  1. I add vuetify
vue add vuetify

? Choose a preset: Default (recommended)

 WARN  conflicting versions for project dependency "sass-loader":
- ^8.0.2 injected by generator "undefined"
- ^10.0.0 injected by generator "vue-cli-plugin-vuetify"
Using newer version (^10.0.0), but this may cause build errors.
  1. I can run the project and add a lot of components, but if i want to put a <v-autocomplete></v-autocomplete> or <v-select> (It must surely have other components), i got this error :
98% after emitting CopyPlugin
 ERROR  Failed to compile with 1 error                               11:51:32 AM
 error  in ./node_modules/vuetify/src/components/VSelect/VSelect.sass
Syntax Error: 
      position: relative
                       ^
      Expected identifier.
   ╷
68 │       position: relative
   │                         ^
   ╵
  stdin 68:25  root stylesheet
      in /home/avi/Downloads/frontend/node_modules/vuetify/src/components/VSelect/VSelect.sass (line 68, column 25)

 @ ./node_modules/vuetify/src/components/VSelect/VSelect.sass 4:14-208 15:3-20:5 16:22-216
 @ ./node_modules/vuetify/lib/components/VSelect/VSelect.js
 @ ./node_modules/vuetify/lib/components/VAutocomplete/VAutocomplete.js
 @ ./node_modules/vuetify/lib/components/VAutocomplete/index.js
 @ ./src/App.vue
 @ ./src/main.ts
 @ multi (webpack)-dev-server/client?http://192.168.1.161:8080&sockPath=/sockjs-node (webpack)/hot/dev-server.js ./src/main.ts

I tried to create a webpack file, downgrade the version of Sass-Loader.. but nothing work.

@jacekkarczmarczyk
Copy link
Author

@av1m install sass@1.32.8 (this exact version)

@av1m
Copy link

av1m commented Apr 19, 2021

Omg, I spent hours on this problem. Thank you so much !!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests