laravel-mix: Vuetify 2 sass compile error
- Laravel Mix Version: 4.1.2
- Node Version: 10.16
- NPM Version: 6.9.0
- OS: Windows 10
Description:
When i try to compile vuetify 2 i get this error:
ERROR in ./node_modules/vuetify/src/styles/main.sass (./node_modules/css-loader!./node_modules/postcss-loader/src??ref--7-2!./node_modules/sass-loader/lib/loader.js??ref--7-3!./node_modules/vue-style-loader!./node_modules/css-loader!./node_modules/sass-loader/lib/loader.js??ref--10-2!./node_modules/vuetify/src/styles/main.sass)
Module build failed (from ./node_modules/sass-loader/lib/loader.js):
undefined
^
Expected newline.
╷
4 │ var content = require("!!../../../css-loader/index.js!../../../sass-loader/lib/loader.js??ref--10-2!./main.sass");
│ ^
╵
stdin 4:114 root stylesheet
in C:\xampp72\htdocs\testvuetify\node_modules\vuetify\src\styles\main.sass (line 4, column 114)
@ ./node_modules/vuetify/src/styles/main.sass 2:14-269
@ ./node_modules/vuetify/lib/framework.js
@ ./node_modules/vuetify/lib/index.js
@ ./app.js
@ multi ./app.js
Steps To Reproduce:
Create a simple vuetify app:
import Vue from 'vue'
import Vuetify from 'vuetify/lib'
Vue.use(Vuetify)
export default new Vuetify()
and try to compile it.
I asked on laracasts too, https://laracasts.com/discuss/channels/elixir/vuetify-sass-compile-error-with-laravel-mix.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 8
- Comments: 32 (1 by maintainers)
@saibotk, your solution worked. Here is the mix configuration:
Thanks.
Check this repo by one of the Vuetify devs: https://github.com/nekosaur/laravel-vuetify. It uses Laravel Mix and Vuetify 2.
Hey,
that is a problem similar to the one, i had tonight and got finally fixed now after many hours and the solution is “pretty” simple.
But keep in mind, that this is not a Laravel Mix bug.
First, you will need to understand, how Mix works, eg. it will add some predefined rules / webpack configs. Secondly, webpack’s rules usually match based on a RegEx, and it will execute all rules. Big note on the ALL here, so no “matching the most specific rule only”, as i thought earlier.
So as the error suggests, the
sass-loadergot some input, which as we can see in your logs, is already processed (it already contains javascript instructions), and suddenly finds some instructions, it cannot handle (var content = ....). So that is what the error is all about.How to fix your webpack config:
Mix adds rules matching all
.sassand.scssfiles, by default. So you can either remove the custom rule you found on the vuetify documentation (and you may need to adjust some configs, but it should work out-of-the-box), or you will need to exclude the vuetify folder from the default rules, like so:Which is, what i did, to also apply some custom PostCSS settings (parent prefixing, to restrict vuetify css, to only be valid inside a specific parent css identifier 😃 )
Side note: Then you would need to separate rules for
.scssand.sasssincesass-loaderhas an option called,indentedSyntaxwhich has to be true forsassfiles and false forscssfiles.I hope this explanation is helpful, as it would have been for me before researching for hours. 👍
I agree that the repos get outdated quick, especially all the 1.x templates out there. But I do think a 2.x repo right now would be a useful scaffold for many of us that just a need a starting point. I’m hoping it’s not a major effort, since I already feel bad asking. If there is anything I can do assist, let me know. I was hoping to document the process, but it was much more complicated than I anticipated and I haven’t been able to get a stable example running. Thanks again for your direction thus far.
Thanks for sharing. I’ve been struggling with this for the past few days. My apologies upfront for asking, but would it possible to post a basic repo with a working example of Laravel 5.8 using Vuetify with Sass variable customizations? Once complete, I’m hoping to document the process for the Vuetify team in hope of adding a Laravel + Vuetify section to the Vuetify docs. It’s pretty complex for those without deep webpack knowledge, but it’s such a powerful combination if we can get it working. Thank you again for your time.
I had to update @filipembcruz 's solution to the following code:
The loader property contains a full path now, so we changed this to check if it contains the sass-loader substring. Sass-loader has a new API for the more recent versions and requires an option
additionalDatainstead ofprependDatanow.Why did I pick this solution instead of declaring the rules directly in the webpack config?
VuetifyLoaderPlugindeclares it’s own rules which I haven’t been able to find or alter yet, and I didn’t find any way to define the variables.sass file by configuration. Adding the rules in the webpack config triggers errors as the following:because the rules are executed twice (1x from vuetify loader plugin, 1x manually added in webpack.config.js).
Altering the rules generated by the vuetify loader plugin with Mix.listen() was the only solution that worked for me.
After many issues, I solve this on Laravel 8.