Laravel-mix: Not able to include less file from node_modules

Created on 25 Jan 2017  路  5Comments  路  Source: JeffreyWay/laravel-mix

Maybe I'm doing something wrong, but I can't include a less file from my node_modules folder.

I took a clean install of Laravel 5.4. Next I did:

  • npm install
  • npm install bootstrap
  • Create file resources/assets/less/app.less
  • Added content: @import "node_modules/bootstrap/less/bootstrap";
  • Changed webpack.mix.js file to:
mix.js('resources/assets/js/app.js', 'public/js')
   .less('resources/assets/less/app.less', 'public/css');
  • Run npm run dev

This gives me this error: Module build failed: Can't resolve './node_modules/bootstrap/less/bootstrap.less'

When I install Laravel Elixir and try the same less file, it works perfectly... Hope someone can help.
Thanks a lot!

Most helpful comment

Yeah it's a less-loader thing. They've had an issue up for a year now about this.

The workaround is to use a tilda, like this:

@import "~bootstrap/less/bootstrap";

All 5 comments

Try @import "../../../node_modules/bootstrap/less/bootstrap";

Okay, that does work. But why does the original path not work for LESS, but it does work for SASS, if you look at the shipped app.scss file, you also see a similar path.

@import "node_modules/bootstrap-sass/assets/stylesheets/bootstrap";

You probably need to add some configuration to the less-loader in order to specify a root path.

Yeah it's a less-loader thing. They've had an issue up for a year now about this.

The workaround is to use a tilda, like this:

@import "~bootstrap/less/bootstrap";

@JeffreyWay Perhaps time to bump laravel-mix's less version up to 3? Nice! You just did - within the last 2 months.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

RomainGoncalves picture RomainGoncalves  路  3Comments

sdebacker picture sdebacker  路  3Comments

rlewkowicz picture rlewkowicz  路  3Comments

Bomavi picture Bomavi  路  3Comments

Cheddam picture Cheddam  路  3Comments