-
Notifications
You must be signed in to change notification settings - Fork 319
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
Using Monorepo packages in a Next.JS app #63
Comments
The root cause of the problem here is that the webpack plugin created for Next isn't running on files outside your next app. I think Next.js aggressively disables custom transformations on Moving the button component to the We will need to contact the Next.js team to help resolve this issue. |
@nmn might be a good idea to add a |
@kevintyj This is not necessarily a NextJS bug, but rather a bug in our NextJS plugin. |
I've also been trying out StyleX within a custom turbo monorepo with a nextjs app inside. Having issues where I don't think stylex is properly configured in the build step, something is missing somewhere as i keep running into "Error: stylex.create should never be called. It should be compiled away.". The important parts of my repo are very similar to the example posted in the original message above. |
@HQ92 Your problem seems a bit different since your compilation isn't triggering at all. NextJS, even with a monorepo, should work as long as you're not using the Would you be able to share some more details about your project? |
I've had a look at the repository over the past week now and found that it was related to something which seems quite silly to be honest. Something that could easily be fixed by updating the docs a little. The issue being that the repository was previously using styled-components and therefore did not have a single css file import for stylex to latch onto. I happened across this issue on the repository, #109, after creating a new nextjs project which happened to come with css modules in which I had no issues until I removed all of the existing css. I think at the moment the solution would be to just update the docs under installation to make clear that there needs to be some sort of css file imported, even if empty at the moment for it to work with nextjs, I don't know if this is also an issue just generally but in the nextjs case it could potentially help any future styled-components or css-in-js users looking to try stylex as an alternative. |
@HQ92 This is a limitation of our NextJS plugin which, along with all our bundler plugins, is still experimental. I've personally reached out to the Next.js team and waiting for someone's help to make the integration better. I'll try to improve the documentation to make this gotcha clear. Also, I think it should be possible to throw better errors in the current plugin in this case. |
We are receiving this error with the most simple usage (no |
@luskin Would you be willing to please share an example project with your setup so I can debug. There are some known issues with |
@nmn we solved this by moving from direct typescript import of the stylex ui from |
@nmn I reproduced for you here: https://github.com/luskin/stylex-issue |
@luskin You're running into a problem in the NextJS plugin where the default typescript configuration isn't set up correctly for TSX files. This has been fixed on |
The issue has been fixed in v0.4.1 and PNPM/NPM monorepos are now correctly working. I've created a PR to your repo with the fix that I tested locally. |
@nmn in my case, the fix not working with 0.4.1. Before, in 0.3.0 throws: |
for some reason it works now. Maybe it was something cache related, since I've tried to reproduce the error and it no longer appears... |
@emilgpa It's likely a cache issue. Please see our "predev" and "prebuild" scripts which delete the |
I was also having this issue with building stylex on vercel in production. It would be quite temperamental in how it would choose to generate styles and apply them. Nuking the .next folder predev and prebuild fixed this, however is this something that will continue to be the case going forward since it does result in longer builds due to something that seems to be a stylex issue? I'm assuming it's something that will be temporary due to stylex being effectively still in beta? |
The original repo from the issue is not available, could you detail the changes you made to get stylex working inside a ui package inside a turborepo? |
@HQ92 We're working on a CLI, which will let you pre-compile a folder into the |
Just ran into the same issue at my end. @nmn thanks for pointing the Next.js issue out numerous times! 🙌
I personally think developing a CLI is probably the best solution as it will probably bypass this entire plugin integration mess. I don't mind using Babel but I'm still not sure what the Is there a timeline of if/when a CLI will be available? |
@Poolshark Next.js uses SWC instead of Babel these days. Many new features are buggy in Babel. Hence the need for a CLI instead of a better integration. SWC plugins are written in Rust which is a much bigger amount of work that we don't need internally so we can't justify investing too much time into that. |
@nmn totally understand. Although, I do not understand why Meta is still relying on Babel these days. As you have said, SWC (or any plugin/compiler written in Rust) is much more performant. I can't remember when Babel did not give me a headache when transpiling TS and Relay ... However, since StyleX now completes the Meta stack (React, Relay, GraphQL, StyleX), it would be a shame not to keep pushing it. I guess with a growing community things will happen automatically. Long story short, I guess your answer is that we should not expect a CLI soon? Or are you referring to plugins only? If there is time I'll try to dig into it, maybe I can help out a bit. |
I'm only referring to a SWC plugin. Any JS-based plugins are fair-game. |
Side point, genuinely excited for this project as soon as I heard about it from Theo.
The problem
I know this library is new and not all edge cases have been covered. However, I am trying to use styleX within a pnpm package. Is this a covered use case or a future one? 🤔
I have two pnpm repos that I've tried this with:
Without using stylex, the component builds correctly and is able to be imported by the nextjs app just fine.
When I launch nextjs:
Again, if I remove stylex (and the onClick) there is no issue the button renders.
How to reproduce
Expected behavior
should be able to run both as a package and then when built and finally when on npmjs.
Please let me know if I have not followed any documentation or have done something incorrectly!
Many thanks for this library!
The text was updated successfully, but these errors were encountered: