stylex: It won't work without the CSS file generated by the css-loader

The problem

In Next.js, if you don’t import any .css file, the styles generated by stylex will not be added to the stylesheet.

How to reproduce

Steps to reproduce:

  1. delete this line https://github.com/facebook/stylex/blob/c9b205750d835cba82b13ef5cdeaf30bbc683f70/apps/nextjs-example/app/layout.tsx#L10
  2. rebuild
  3. not working because not exists.next/static/css

Expected behavior

Is any .css file necessary? Can it be omitted?

Environment (include versions). Did this work in previous versions?

https://github.com/facebook/stylex/blob/c9b205750d835cba82b13ef5cdeaf30bbc683f70/apps/nextjs-example/package.json

About this issue

  • Original URL
  • State: open
  • Created 7 months ago
  • Reactions: 1
  • Comments: 15 (15 by maintainers)

Most upvoted comments

Yes. This is a known issue with the Nextjs Plugin. For now, that one CSS file is required. Use it for global styles and resets.

@nmn Okay, yes. I wasn’t thinking about virtual modules, but yeah, you’re right. I will write down how I could do it that way, but mostly I will start on the other tasks.

@nmn

Outside of this, I’m not really sure @timwehrle. Sorry, I don’t really have more guidance for you.

No problem!

This should be possible by automatically injecting an import for the css file while transforming JS files. I did something similar while making StyleX work with Svelte. https://github.com/nmn/sveltekit-stylex

Yeah, I’ll see what I can do. Thank you!

@timwehrle Yes. Both of those are currently blocked on changes to the Babel plugin that I will be making. I wrote an RFC about it in Github Discussions

https://github.com/facebook/stylex/discussions/111

Also, didn’t mean to close this task. Reopening.

@nmn

Thank you for the overview. I will get back to you if I need any further help or clarification.

@nmn I can work on this.