vite icon indicating copy to clipboard operation
vite copied to clipboard

SASS and SCSS Undefined variable in production build after upgrading from v4 to v5

Open nsmithdev opened this issue 9 months ago • 3 comments

Describe the bug

After upgrading from v4 to v5 I am receiving lots of error related to undefined variables errors only in production build. No config change were made only npm package version upgrade.

Before: "vite": "^4.4.8", After: "vite": "^5.0.0",

I can still compile with scss manually with command: .\node_modules\.bin\sass --load-path=node_modules .\src\assets\styles\app.scss

Did something change with how scss variable scoping works etc? I can't find anything in the release notes.

I wanted to check if there was a simple solution before creating a reproduction. I'll post it soon as I can create one.

Reproduction

a

Steps to reproduce

No response

System Info

Windows and sass 1.64.2 though I have tried updating it also.

Used Package Manager

npm

Logs

error during build: Error: Undefined variable.

Validations

nsmithdev avatar May 10 '24 18:05 nsmithdev

It seems to be treating all my scss files as individual entry points and or trying to compile them individually even if they are not referenced by any react code. I was able to rename one of the files to a random name 99common99.scss and it's still trying to compile it. When I create a new project i'm not seeing it behave the same way.

nsmithdev avatar May 10 '24 19:05 nsmithdev

Ok I tracked it down to a usage of URL() with import.meta.url which was causing it to try and compile all my scss files under assets individually.

<img className='logo' src={ getAssetUrl(`companyLogos/${ user.companyLogoName }`) } alt='altLogo'/>

export const getAssetUrl = (path) => {
  return new URL(`../assets/${ path }`, import.meta.url).href
}

Updating ../assets/${ path } to ../assets/companyLogos/${ path } made it stop compiling the unreferenced scss files.

nsmithdev avatar May 10 '24 20:05 nsmithdev

Hello @nsmithdev. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with needs reproduction will be closed if they have no activity within 3 days.

github-actions[bot] avatar May 13 '24 07:05 github-actions[bot]