-
Notifications
You must be signed in to change notification settings - Fork 361
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
'use client' #1049
Comments
Edit: It does not. I'm wondering if this is something Microbundle should support though, as directives are per-file, so if you were to say bundle a bunch of components with Microbundle, all would be affected by that directive. I'm not sure what the expected behavior here would be. |
The only way I can think of to do this would be to string-replace // replace directive with a side effecting statement to keep it in-place during minification:
code = code.replace(/(\{[\n\s]*)(['"])use client\2([;\s])/g, `$1var{}=_USE_CLIENT_$3`);
// then minify:
let minified = (await terser.minify(code)).code;
// then replace the statement back:
minified = minified.replace(/(\{[\n\s]*)var\s*{\s*}\s*=\s*_USE_CLIENT_([;\s])/g, `$1"use client"$2`); |
any solution planned @developit ? this might become a real issue once maintainer switch to Next.js app folder |
terser also has @clementroche does it help to add a {
"minify": {
"compress": {
"directives": false,
}
}
} We might also need rollup-plugin-preserve-directives 🤔 Also see the rollup issue about the subject: rollup/rollup#4699 |
Now i realise that the issue comes from rollup itself not directly from microbundle, i'm gonna take a look at the thread you shared, thank you |
I tried both solutions @ForsakenHarmony, still have this warning pretty sure |
Yes, Microbundle's Rollup configuration is not open to configuration. However, you can of course patch Microbundle's config from |
Personally, I would just like a way to silence that error for now. Having a thousand lines like this,
makes it hard to find when there are actual errors that prevent bundling. I'm trying to figure out how to directly patch microbundle.js in node_modules, where the config lives, but I think I'm running into issues with yarn caching the files so my edits aren't causing changes :(. |
You can edit the relevant files then use patch-package to create a patch that you can track in version control. It will be reapplied on install |
Sorry, I didn't see this. Make sure you're editing Yarn v1 has no caching, no idea about v2+ though. |
Hi, I'm the maintainer of react-lenis package and some people complain about using the library in next.js app context usage.
In fact it requires 'use client' directive on top of the file but I noticed that it's ignored by microbundle "Module level directives cause errors when bundled, 'use client' was ignored."
Do you have a solution for that ?
https://github.com/studio-freight/lenis/issues/170
The text was updated successfully, but these errors were encountered: