question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Fails compilation in scss files

See original GitHub issue

Describe the Bug

I am using @angular-builders/custom-webpack to extend the compilation of the scss files in order to use postcss and the plugin postcss-modules

Currently, when I try to serve the project these errors are displayed in the terminal:

image

I think the issue is the component.scss files are being compiled twice, one for the default compiler and the other one by my custom webpack config: extra-webpack.config.js.

Minimal Reproduction

Here is my project: https://github.com/gquinteros93/angular-css-modules

Expected Behavior

I expect my scss files will be compiled with my custom webpack rule.

Environment


Libs
- @angular/core version: 8.2.0
- @angular-devkit/build-angular version: 0.803.24
- @angular-builders/custom-webpack": "8.2.0"
- @angular-builders/dev-server": "7.3.1"

For Tooling issues:
- Node version: v10.9.0
- Platform:  Mac

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
gquinteros93commented, Apr 6, 2020

Hi @just-jeb , thanks for you help, I follow the same approach as: https://github.com/angular/angular-cli/issues/8427#issuecomment-576263052

And I was able to extend postcss 🎉 : extra-webpack.config.js :

const postcssModules = require('postcss-modules');

module.exports = (config, options) => {

    const scssRule = config.module.rules.find(x => x.test.toString().includes('scss'));
    const postcssLoader = scssRule.use.find(x => x.loader === 'postcss-loader');
    const pluginFunc = postcssLoader.options.plugins;
    const newPluginFunc = function () {
        var plugs = pluginFunc.apply(this, arguments);
        plugs.splice(plugs.length - 1, 0, postcssModules({ generateScopedName: "[hash:base64:5]" }));
        return plugs;
    }
    postcssLoader.options.plugins = newPluginFunc;

    return config;
};

Now I need to extend posthtml-loader in order to use posthtml-css-modules to replace the classes names by their corresponding hashed names.

I will research if it possible but If you already know or have an idea about how to do it, it’s more than welcome.

Thanks!!!

0reactions
just-jebcommented, Apr 6, 2020

@gquinteros93

I got the following error:

Yeah sorry I mislead you. You need to use @angular-builders/custom-webpack:dev-server. In any case @angular-builders/dev-server is deprecated.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Failed compiling sass file - css - Stack Overflow
I have an error when I try to compile ...
Read more >
SCSS compiling with webpack failed
I'm using Webpack in order to build all my stylesheet files. Actual behavior. Build fails with this error : enter image description here....
Read more >
Sass compiles CSS from SASS or SCSS files
Description: Converts SCSS or Sass files to CSS. Common Options: -I, --load-path PATH ... --stop-on-error If a file fails to compile, exit immediately....
Read more >
Install Sass
When you install Sass on the command line, you'll be able to run the sass executable to compile .sass and .scss files to...
Read more >
SCSS Compiler - phpBB Services
The compiler reads the .scss files and usually generates one .css file which ... If the file fails to compile, it should generate...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found