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

How to add node_modules to the include path? #554

Closed
lbjones opened this issue Mar 10, 2017 · 6 comments
Closed

How to add node_modules to the include path? #554

lbjones opened this issue Mar 10, 2017 · 6 comments

Comments

@lbjones
Copy link

lbjones commented Mar 10, 2017

  • Laravel Mix Version: 0.8.8
  • Node Version (node -v): 6.10.0
  • NPM Version (npm -v): 3.10.10
  • OS: Mac OS

Description:

I am trying to use an NPM package called material-components-web. When I include the main .scss file, it includes other dependencies within itself. Here is the problem though: it doesn't use a path relative to itself, the path is relative to node_modules. According to the official documentation:

NOTE: The components' Sass files expect that the node_modules directory containing the @Material scope folder is present on the Sass include path.

I've tried everything I can think of trying to merge using mix's webpackConfig. Webpack's documentation is a little confusing, to say the least.

Has anyone figured this out?

Thanks for your time!

Steps To Reproduce:

On command line,
npm install material-components-web

In my app.scss file,
@import "node_modules/material-components-web/material-components-web";

Then when I try to compile,
npm run dev

I get this:
Module build failed: ModuleBuildError: Module build failed: @import "@material/animation/mdc-animation"; ^ File to import not found or unreadable: @material/animation/mdc-animation.

@JeffreyWay
Copy link
Collaborator

Give this a try in your webpack.mix.js file.

mix.sass('resources/assets/sass/app.scss', 'css', {
    includePaths: ['node_modules']
});

@lbjones
Copy link
Author

lbjones commented Mar 10, 2017

Thank you!!! I'm not sure why I couldn't find that!

The imports now work in the .scss file, but I'm still getting errors when trying to import from a .vue file, such as:

<style lang="scss">
@import '~@material/checkbox/mdc-checkbox';
</style>
Module build failed:
@import "@material/animation/functions";
^
      File to import not found or unreadable: @material/animation/functions.

@Jhersyvb
Copy link

Jhersyvb commented May 2, 2020

For laravel-mix 5 try in your webpack.mix.js

mix
  .sass('resources/sass/app.scss', 'public/css/sass.css', {
    sassOptions: {
      includePaths: ['node_modules'],
    },
  })

@webpixels
Copy link

For laravel-mix 5 try in your webpack.mix.js

mix
  .sass('resources/sass/app.scss', 'public/css/sass.css', {
    sassOptions: {
      includePaths: ['node_modules'],
    },
  })

It works in v6 as well \m/

@djmtype
Copy link

djmtype commented Apr 22, 2021

This works but the node module's css gets imported before all my other styles even though I have it importing into a sass file towards the end.

@thecrypticace
Copy link
Collaborator

Unfortunately this is a sass problem with mixed sass & css imports: #2793

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

No branches or pull requests

5 participants