macaron-css / macaron

Compiler-augmented typesafe CSS-in-JS with zero runtime, colocation, maximum safety and productivity
https://macaron.js.org/
MIT License
735 stars 16 forks source link

Vite build watch doesn't work with Macaron #44

Closed dugip closed 1 year ago

dugip commented 1 year ago

When using vite build --watch, the initial build works, but if you change the files to re-trigger a build, Macaron style generation will fail with the following error:

[commonjs] Could not load /home/projects/vitejs-vite-ggwk6m/src/extracted_1bkv64o.css.ts: ENOENT: no such file or directory, open '/home/projects/vitejs-vite-ggwk6m/src/extracted_1bkv64o.css.ts'

Repro repo:

Steps to test:

Pagebakers commented 1 year ago

Same issues here with Vite, any known work around for this? Really like to get going with this lib but this is blocking me.

Mokshit06 commented 1 year ago

Thanks for reporting this. I have been looking into what is causing it, and it seems to be a change in the internals of vite. I haven't been able to come up with a fix yet, but using a lower version of vite should fix it in the meanwhile

Pagebakers commented 1 year ago

I see, which version exactly? I'll downgrade for now.

Tried 3.2.7 and 2.7.0 but still get the same errors.

Mokshit06 commented 1 year ago

Hm yeah it looks like vite build --watch doesn't work, but vite's HMR does if you are using a framework that makes use of that. Looks like an issue with how macaron resolves files – will try to find a fix for this

dugip commented 1 year ago

Any news here @Mokshit06? Is there I can help?

Mokshit06 commented 1 year ago

Unfortunately I didn't get the time to work on it. Will try to see if I can fix it this week. If you want to try working on it, I would start by adding breakpoints/logs to the resolveId and load callbacks, and seeing when they don't resolve with watch mode. This probably has something to do with the resolverCache/cssMap/idToPluginData.

Mokshit06 commented 1 year ago

This should be fixed in the latest version. The issue was that macaron was clearing the cache before every build, so every time you changed something, it would clear the cache in watch mode and then vite couldn't resolve the file.