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

Failed to compile: node:fs/promises - Error when trying to colocate styles in a MDX project #255

Open
clovis-rosa opened this issue Jan 4, 2025 · 5 comments
Labels
bug Something isn't working

Comments

@clovis-rosa
Copy link

Hi guys! First, thanks for putting the time to work on this project!

I'm playing around next-yak in a MDX project where the following error occurred while trying to colocate the styles:

"Module build failed: UnhandledSchemeError: Reading from "node:fs/promises" is not handled by plugins (Unhandled scheme).
Webpack supports "data:" and "file:" URIs by default.
You may need an additional plugin to handle "node:" URIs."

Here is a repo example: https://github.com/clovis-rosa/nextjs-mdx-blog-next-yak

Please see the Page.tsx, comment the import Article line and uncomment the styled block on the bottom of the page to see the error.

As I still a bit confused with the "use server" directive in Next, I add it to the top. The error goes away, but no styles are applied to that specific HTML element.

@Mad-Kat
Copy link
Collaborator

Mad-Kat commented Jan 4, 2025

Hey @clovis-rosa

Thank you very much for the detailed issue description and for taking the time to create a reproduction. Upon first glance it looks for me that this is related to #112 where we created a bug for next.js in vercel/next.js#67591.

I had again a look yesterday at the problem but I didn't find a fast solution (yet). I will keep you in the loop.

@jantimon
Copy link
Collaborator

jantimon commented Jan 5, 2025

node:fs/promises is only imported for a rsc - maybe our transform confuses next.js and it handles it like a client component?

@Mad-Kat
Copy link
Collaborator

Mad-Kat commented Jan 5, 2025

Yes exactly my thought. If we could say to next.js that our import is not a client component but a valid CSS file it should work

@clovis-rosa
Copy link
Author

Just a small update: everything working fine after I add "use server" on top of the file posts-queries.ts. I guess @Mad-Kat may be in the right direction on this one.

@jantimon
Copy link
Collaborator

jantimon commented Jan 7, 2025

I believe this could be the same bug as explained in this #112 (comment)

  1. In the next.js RSC compilation layer, Next.js allows direct use of node:fs/promises for file system operations
  2. When next-yak processes the styled components, it seems to trigger a recompilation in the next.js browser compilation layer
  3. The browser layer compilation encounters the node:fs/promises import and fails because:
    • Node.js modules can't run in the browser
    • Webpack in the browser layer isn't configured to handle node: scheme URLs

@Mad-Kat Mad-Kat added the bug Something isn't working label Jan 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

No branches or pull requests

3 participants