-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
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
dynamic import is undefined when building with "modern-compiler" and sass-embedded
#19052
Comments
I have encountered the same problem: [vite:css] [sass] Cannot read properties of undefined (reading 'initAsyncCompiler')
file: /GitHub/weapp-vite/apps/vite-native/app.scss
node:internal/process/promises:392
new UnhandledPromiseRejection(reason);
^
UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "#<Object>".
at throwUnhandledRejectionsMode (node:internal/process/promises:392:7)
at processPromiseRejections (node:internal/process/promises:475:17)
at process.processTicksAndRejections (node:internal/process/task_queues:106:32) {
code: 'ERR_UNHANDLED_REJECTION'
}
Node.js v22.12.0 Reproductionhttps://github.com/weapp-vite/weapp-vite/tree/main/apps/vite-native Steps to reproduce
Used Package Managerpnpm System Info System:
OS: macOS 15.2
CPU: (14) arm64 Apple M4 Pro
Memory: 97.59 MB / 24.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 22.12.0 - ~/.nvm/versions/node/v22.12.0/bin/node
Yarn: 1.22.22 - ~/.nvm/versions/node/v22.12.0/bin/yarn
npm: 10.9.0 - ~/.nvm/versions/node/v22.12.0/bin/npm
pnpm: 9.15.1 - ~/.nvm/versions/node/v22.12.0/bin/pnpm
Browsers:
Chrome: 131.0.6778.205
Safari: 18.2
npmPackages:
@vitejs/plugin-legacy: ^6.0.0 => 6.0.0
rollup: ^4.29.1 => 4.29.1 |
@cod1r It doesn't reproduce on my machine. Are you using some loaders like tsx or ts-node? |
i think you need to have sass-embedded installed which causes it to pass a different path to makeModernSassFunction or whatever it's called |
@cod1r Your reproduction contains
Are you using other runtimes than Node? e.g. Deno, Bun |
no. i just imported a sass file and did a vite build or w/e |
oh im an idiot. the link is not react lmao |
gimme one sec |
ok, the stackblitz thing is weird. but basically just have sass, sass-embedded, and try to build with those packages locally. probably will error due to above problem |
@cod1r would you make a GitHub repo that reproduces the error? |
i can ye. just gotta get day20 aoc. gimme some time |
seems like @ hi-ogawa had some reproducible repos linked in the PR i made |
I don't think hi-ogawa's reproduction is the one that reproduces the |
Hello @cod1r. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with |
👀 |
Not a reproduction, but it seems sass-embedded exports mjs file which is being used instead of default cjs. |
ok this is a problem with tsx lmao |
This issue probably should be closed. If I just don't use tsx or ts-node, then the build works fine. Sucks that now I have to switch my build script to javascript but whatever. |
I'm encountering the same issue after updating my vite config to use the below snippet. @cod1r In your investigation, did you bother trying to figure out how TSX is causing the issue? TSX is super convenient and I think I'd rather stick with the legacy sass api for now than switch off. If you have any info, I'd be glad to include it in a TSX bug report.
|
I'm not sure if it's a bug, but tsx resolves imports differently than modern node versions. When vite tries to import sass/sass-embedded, it's expecting an object with a 'default' key, but there is none when using tsx, which is why Another solution might be to use another runtime like deno/bun to run typescript scripts instead of using tsx/ts-node. |
While yes, this is a TSX or TypeScript-itself issue, this kinda blocks SSR apps in ESM. For dev servers, the Vite SSR Guide uses a Vite middleware on your backend app... of which, if you're using TypeScript ESM; won't work. And the workaround is pretty simple... https://github.com/vitejs/vite/blob/main/packages/vite/src/node/plugins/css.ts#L2483-L2485 ^ these lines could just become: const sassImport = await import(pathToFileURL(sassPath).href);
const sass: typeof Sass = sassImport.default ?? sassImport; // workaround from #19052
compilerPromise ??= sass.initAsyncCompiler() Then a backend using TSX could still run the Vite dev server with modern-compiler. Otherwise, we're kinda just waiting for a resolution on privatenumber/tsx#442 ... which seems kinda low-priority to the TSX team, or might even be a TypeScript design decision. |
I'm fine with having a workaround merged in Vite. We just need a reproduction so that we can understand why that workaround is needed and we don't break it accidently in future. |
I’m new to Vite [this is my first project using it, coming from the Webpack/CJS world], so if anyone reading this wants to implement that change and write the test for it… go ahead. I’m happy to help out or provide an example/reproduce repo. Otherwise might be a while before I get to it 🙃 |
Describe the bug
I expect to do builds without any crashes relating to "sass" being an undefined import.
The actual behavior is that in css.ts, the dynamic import is expecting properties to be on the default export but instead properties are exported individually (named exports w/e you want to call it).
Reproduction
stackblitz link wasn't working out. had a different sass-embedded error lmaojust have sass files and try importing them and then doing a vite build with sass-embedded. the sass-embedded dynamic import will try to grab a default export but sass embedded doesn't have one
Steps to reproduce
System Info
Used Package Manager
yarn
Logs
The text was updated successfully, but these errors were encountered: