angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

Configure Sass-loader to include node_modules in includePath

Open alexciesielski opened this issue 10 years ago • 17 comments

angular-cli: 1.0.0-beta.15 node: 6.5.0 os: linux x64

I want to compile the scss file from bootstrap-material-design by putting it in the apps[0].styles[] array but I get the following message:

ERROR in ./~/css-loader!./~/postcss-loader!./~/sass-loader!./~/bootstrap-material-design/scss/bootstrap-material-design.scss                                               
Module build failed:                                                                                                                                                       
@import "bootstrap/scss/variables"; // from bootstrap node_module                                                                                                          
^                                                                                                                                                                          
      File to import not found or unreadable: bootstrap/scss/variables                                                                                                     
Parent style sheet: /home/ciesielskico/Documents/Git/reports/node_modules/bootstrap-material-design/scss/_variables.scss                
      in /home/ciesielskico/Documents/Git/reports/node_modules/bootstrap-material-design/scss/_variables.scss (line 45, column 1)       
 @ ./~/bootstrap-material-design/scss/bootstrap-material-design.scss 4:14-148                                                                                              
 @ multi styles                              

On their documentation it says to put node_modules in the includePath of the sass-loader.

Is it possible? If yes, how?

alexciesielski avatar Sep 21 '16 12:09 alexciesielski

@ciesielskico - the issue tracker is for project bugs and project feature requests as noted in CONTRIBUTING.md. For better support, consider creating a question on StackOverflow with all the details.

JanStureNielsen avatar Sep 21 '16 18:09 JanStureNielsen

Maybe try prepending "~" to the import path? See here:

https://github.com/jtangelder/sass-loader#imports

ghost avatar Sep 22 '16 18:09 ghost

What would be the best way to import the common sass/scss helpers (i.e: mixins, variables), instead of importing from like '../../../styles/variables.scss'?

for such use case, scssLoader.includePaths option works great, but how can we configure this settings in angular-cli project?

zhenwenc avatar Sep 30 '16 11:09 zhenwenc

@dbandstra's suggestion of using ~ is the best way of addressing modules in node_modules.

@zhenwenc there is no way currently to include paths.

filipesilva avatar Oct 05 '16 20:10 filipesilva

including relative paths is not maintainable.. like @zhenwenc mentioned we could use includePaths for third party library scss mixins.. at the moment I'm having to depend on the file tree to look for node_modules

hope we can fix this.. or if anyone has found a better way of doing things please drop the suggestion

danieljoffe avatar Oct 13 '16 23:10 danieljoffe

In my case bootstrap material design tries to import bootstrap variables like this: @import "bootstrap/variables"; Of course I can't modify the regarding file because it's a 3rd party dep. What would you suggest to do in this case if I can't specify importPaths explicitly ?

andreasgrimm avatar Oct 31 '16 16:10 andreasgrimm

Why the issue is closed when its not resolved? Like @dannyk08 and @zhenwenc suggested there should be a way to specify it

adilmughal avatar Nov 22 '16 22:11 adilmughal

This is really annoying - what's the problem to expose importPaths ?

skiraikou avatar Nov 24 '16 15:11 skiraikou

Here is what I am currently doing (not perfect, but consider it is a workaround), please let me know if there is any other better solutions:

To import the common sass/scss helpers (i.e: mixins, variables), basically locate it from the root directory to avoid ../../∞/../styles/variables:

@import 'src/assets/styles/variables';
@import 'src/assets/styles/mixins';

To import from 3rd party libraries (addressing modules in node_modules):

@import '~bourbon/app/assets/stylesheets/bourbon';
@import '~bourbon-neat/app/assets/stylesheets/neat';

Hope it helps. :-)

zhenwenc avatar Dec 12 '16 02:12 zhenwenc

@filipesilva This ~ forces the other user of the libraries to use webpack or do other webpack. This was the only way to distribute a reusable library and expose my SASS. So ~ is not a good solution. Why is it so hard to expose includePath ?

yogeshgadge avatar Jul 13 '17 15:07 yogeshgadge

@yogeshgadge includePath has been around in the CLI for a while now: https://github.com/angular/angular-cli/wiki/stories-global-styles

filipesilva avatar Jul 17 '17 10:07 filipesilva

I couldn't get the includePaths to work with third-party libraries either. The only way I could get this to work is to use follow @zhenwenc advice. The below includePaths property doesn't work.

"stylePreprocessorOptions": {
        "includePaths": [ "./node_modules/node-neat/node_modules/bourbon-neat/core" ]
      },

I still receive a "File to import not found or unreadable: neat." In my styles.scss, I am using the following import statement:

@import "neat";

haydenhancock avatar Aug 01 '17 03:08 haydenhancock

@haydenhancock Try this and make sure it is inside apps:[{

  "stylePreprocessorOptions": {
    "includePaths": [
      ".",
      "../node_modules"
    ]
  },

and the import as

@import "bourbon-neat/core/neat"

yogeshgadge avatar Aug 03 '17 18:08 yogeshgadge

@yogeshgadge This didn't work for me.

File to import not found or unreadable: bourbon-neat/core/neat.

The following did work for me though:

"stylePreprocessorOptions": {
    "includePaths": [ "../node_modules/node-neat/node_modules/bourbon-neat/core" ]
 },

and the import as:

@import "neat";

haydenhancock avatar Aug 04 '17 00:08 haydenhancock

I had the same with bootstrap 4's sass files. The error in the build output shows that it is looking for the sass modules in $PROJECT/src/~ when it should look in $PROJECT/~. Prepending .. in includePaths fixes that. This should be added to the documentation. I'd PR but I don't know how to contribute to wikis.

ohcibi avatar Aug 14 '17 09:08 ohcibi

This is really annoying - what's the problem to expose importPaths ?

please read comments above why

pro100skm avatar Aug 04 '19 18:08 pro100skm

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.