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

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

Closed
7 tasks done
nsmithdev opened this issue May 10, 2024 · 3 comments
Closed
7 tasks done

Comments

@nsmithdev
Copy link

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
Copy link
Author

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
Copy link
Author

nsmithdev commented May 10, 2024

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.

Copy link

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 github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale May 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants