12

I was able to successfully configure a new Vue project using the 3.0 version of the CLI to use sass-resource-loader a few weeks ago using the information posted here: Using sass-resources-loader with vue-cli v3.x

However, after updating everything today I'm encountering the following error when running npm run serve:

TypeError: Cannot read property 'scss' of undefined

the only options that seem to be getting passed into .tap(options) are:

{ compilerOptions: { preserveWhitespace: false } }

I don't currently know enough about chainWebpack to effectively debug, but I'm working on it. If anyone has any insights into what's changed to cause this error, it'd be greatly appreciated.

my vue.config.js:

const path = require('path') module.exports = { chainWebpack: (config) => { config .module .rule('vue') .use('vue-loader') .tap((options) => { console.log(options) options.loaders.scss = options.loaders.scss.concat({ loader: 'sass-resources-loader', options: { resources: [ path.resolve('./src/scss/_variables.scss'), path.resolve('./src/scss/_mixins.scss') ] }, }) return options }) config .module .rule('scss') .use('sass-resources-loader') .loader('sass-resources-loader') .options({ resources: [ path.resolve('./src/scss/_variables.scss'), path.resolve('./src/scss/_mixins.scss') ] }) } } 
1

1 Answer 1

8
+50

You use [email protected], this probably means that your project uses [email protected] Since version 15, the vue-loader does not need additional configs for loaders. You can configure only your main webpack loaders.

const path = require('path') module.exports = { chainWebpack: (config) => { config .module .rule('scss') .use('sass-resources-loader') .loader('sass-resources-loader') .options({ resources: [ path.resolve('./src/scss/_variables.scss'), path.resolve('./src/scss/_mixins.scss') ] }) } } 

You can also inspect webpack configs using the vue inspect or ./node_modules/.bin/vue-cli-service inspect commands.

Sign up to request clarification or add additional context in comments.

5 Comments

I tried your solution but I get this: Module build failed (from ./node_modules/sass-loader/lib/loader.js): undefined ^ Undefined variable: "$brand-color". in C:\dev\git\vue-typescript-test\src\components\HelloWorld.vue (line 60, column 10) This is on a fresh VueCli project
Have the same issue as @ConstantinChirila
@Victor i managed to do it without the sass-resource-loader. In your vue.config.js add this: module.exports = { css: { loaderOptions: { sass: { data: @import "@/scss/_config.scss"; } } } } You can check more in here: cli.vuejs.org/guide/css.html#pre-processors
Updating last @ConstantinChirila comment : You should now use "prependData" instead of "data" which is deprecated now (sass-loader v8)
This solution will reimport _config.scss in every lang="scss" style you define. (your resulting bundle will have multiple duplicated style tags). not an optimal solution

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.