laravel-mix: [6.x.x] Mix wont compile if child scss use assets relative to root // SourceMaps are False by default

  • Laravel Mix Version: 6.0.0
  • Node Version: v14.15.3
  • NPM Version: 6.14.9
  • OS: Windows 10

Description:

i’ve upgraded a project from Mix 4 to 6, i had some url with this format

src: url('../../assets/fonts/font.woff2') format('woff2'),

which were resolved and moved correctly. but after the update, i had to change it to

src: url('../assets/fonts/font.woff2') format('woff2'),

otherwise mix wont compile. The very same happen with vendor dependency, for example i used to import @import "~rpg-awesome/scss/rpg-awesome"; without issues, but now i get this error:

ERROR in ./resources/sass/app.scss Module build failed (from ./node_modules/mini-css-extract-plugin/dist/loader.js): ModuleBuildError: Module build failed (from ./node_modules/css-loader/dist/cjs.js): Error: Can't resolve '../fonts/rpgawesome-webfont.eot?v=0.1.0' in 'G:\laragon\www\tdl_laravel\resources\sass' at finishWithoutResolve (G:\laragon\www\tdl_laravel\node_modules\enhanced-resolve\lib\Resolver.js:293:18) at G:\laragon\www\tdl_laravel\node_modules\enhanced-resolve\lib\Resolver.js:362:15 at G:\laragon\www\tdl_laravel\node_modules\enhanced-resolve\lib\Resolver.js:410:5 at eval (eval at create (G:\laragon\www\tdl_laravel\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:16:1) at G:\laragon\www\tdl_laravel\node_modules\enhanced-resolve\lib\Resolver.js:410:5 at eval (eval at create (G:\laragon\www\tdl_laravel\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:27:1) at G:\laragon\www\tdl_laravel\node_modules\enhanced-resolve\lib\DescriptionFilePlugin.js:87:43 at G:\laragon\www\tdl_laravel\node_modules\enhanced-resolve\lib\Resolver.js:410:5 at eval (eval at create (G:\laragon\www\tdl_laravel\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:16:1) at G:\laragon\www\tdl_laravel\node_modules\enhanced-resolve\lib\forEachBail.js:16:12 at G:\laragon\www\tdl_laravel\node_modules\enhanced-resolve\lib\AliasPlugin.js:103:14 at next (G:\laragon\www\tdl_laravel\node_modules\enhanced-resolve\lib\forEachBail.js:14:3) at forEachBail (G:\laragon\www\tdl_laravel\node_modules\enhanced-resolve\lib\forEachBail.js:24:9) at G:\laragon\www\tdl_laravel\node_modules\enhanced-resolve\lib\AliasPlugin.js:37:5 at _next0 (eval at create (G:\laragon\www\tdl_laravel\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:8:1) at eval (eval at create (G:\laragon\www\tdl_laravel\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:30:1) at processResult (G:\laragon\www\tdl_laravel\node_modules\webpack\lib\NormalModule.js:583:19) at G:\laragon\www\tdl_laravel\node_modules\webpack\lib\NormalModule.js:676:5 at G:\laragon\www\tdl_laravel\node_modules\loader-runner\lib\LoaderRunner.js:397:11 at G:\laragon\www\tdl_laravel\node_modules\loader-runner\lib\LoaderRunner.js:252:18 at context.callback (G:\laragon\www\tdl_laravel\node_modules\loader-runner\lib\LoaderRunner.js:124:13) at Object.loader (G:\laragon\www\tdl_laravel\node_modules\css-loader\dist\index.js:155:5) at runMicrotasks (<anonymous>) at processTicksAndRejections (internal/process/task_queues.js:93:5)

it is intended? it seems strange to not points the url relative paths where the files resides, it seems the “…/…/” messes up the url rewriting

Steps To Reproduce:

composer create-project laravel/laravel testbug change in package.json "laravel-mix": "^6", npm i

create resources/sass/app.scss and resources/sass/example/test.scss in test.scss do a simple:

@font-face {
    font-family: 'base-text';
    src: url('../../assets/fonts/base-text.woff') format('woff'),
    url('../../assets/fonts/base-text.woff2') format('woff2');
    font-weight: normal;
    font-style: normal;
}

obviusly, create folder resources/assets/fonts and put you test font in there (it can be whatever you prefer, img, svg, the same problem occur)

compile and you’ll get:

ERROR in ./resources/sass/app.scss
Module build failed (from ./node_modules/mini-css-extract-plugin/dist/loader.js):
ModuleBuildError: Module build failed (from ./node_modules/css-loader/dist/cjs.js):
Error: Can't resolve '../../assets/fonts/base-text.woff' in 'G:\xxx\testbug\resources\sass'

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 6
  • Comments: 17 (1 by maintainers)

Most upvoted comments

Working on this today. Should hopefully have a tagged patch out shortly.

Can confirm I was having similar issues with url() inside of child SCSS files and adding mix.sourceMaps() fixed it.

@ArjunKishore

I am still having this issue with Laravel mix version 6.0.27

Will appreciate it if anyone could point me in the right direction to resolve this.

I have the same issue with Laravel mix version 6.0.29. Did you find a solution?

Adding .sourceMaps() or .sourceMaps(true) does nothing for me. For every url() which has a path relative to the root the resolve fails. Unfortunately I don’t have the time to debug this right now, but currently this makes laravel-mix 6.0 unusable for me.