-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
[Vite] Noisy error “Module level directives cause errors when bundled, "use client" was ignored.” when running remix vite:build
on a project that includes a dependency file which includes the "use client"
directive.
#8891
Comments
It would be nice if it was handled automatically, but I've been doing this in the meantime: // vite.config.ts
import { defineConfig } from "vite";
export default defineConfig({
build: {
rollupOptions: {
onwarn(warning, warn) {
// Suppress "Module level directives cause errors when bundled" warnings
if (warning.code === "MODULE_LEVEL_DIRECTIVE") {
return;
}
warn(warning);
},
},
},
// your other Vite config stuff...
}); You probably already found something similar, but dropping it here just in case it's helpful for somebody. |
Thanks for raising this. Fixed by #8897. |
🤖 Hello there, We just published version Thanks! |
🤖 Hello there, We just published version Thanks! |
awesome it's works , thanks bro 👍 |
components that use react hook or memo... <!-- How to write a good PR title: - Follow [the Conventional Commits specification](https://www.conventionalcommits.org/en/v1.0.0/). - Give as much context as necessary and as little as possible - Prefix it with [WIP] while it’s a work in progress --> ## Self Checklist - [x] I wrote a PR title in **English** and added an appropriate **label** to the PR. - [x] I wrote the commit message in **English** and to follow [**the Conventional Commits specification**](https://www.conventionalcommits.org/en/v1.0.0/). - [x] I [added the **changeset**](https://github.com/changesets/changesets/blob/main/docs/adding-a-changeset.md) about the changes that needed to be released. (or didn't have to) - [x] I wrote or updated **documentation** related to the changes. (or didn't have to) - [x] I wrote or updated **tests** related to the changes. (or didn't have to) - [x] I tested the changes in various browsers. (or didn't have to) - Windows: Chrome, Edge, (Optional) Firefox - macOS: Chrome, Edge, Safari, (Optional) Firefox ## Related Issue #2456 (not close or fixes) <!-- Please link to issue if one exists --> <!-- Fixes #0000 --> ## Summary <!-- Please brief explanation of the changes made --> - Add `use client` directives ## Details <!-- Please elaborate description of the changes --> - I add `use client` directives to all component filds - I didn't see any code that used the window API. - ~~I am not sure about files that `Radix` exports without additional logic.~~ - As suggested in the comments, I tested it in the code sandbox and found no problems. - Currently, directives have been added including this one. When I checked, I saw that hooks, etc. were used in the internal implementation. ```typescript // page.tsx import * as Dialog from "@radix-ui/react-dialog"; import * as Tooltip from "@radix-ui/react-tooltip"; import * as Separator from "@radix-ui/react-separator"; import * as Switch from "@radix-ui/react-switch"; import * as VisuallyHidden from "@radix-ui/react-visually-hidden"; export default function Home() { return ( <main className="flex min-h-screen flex-col items-center justify-between p-24"> {/* code with radix-ui ...*/} </main> ); } ``` - Add the changeset - To ignore `Module level directives cause errors when bundled` warnings, I returned onWarn early when the warning appeared.It seemed appropriate to write it inside the `generateConfig`. ### Breaking change? (Yes/No) <!-- If Yes, please describe the impact and migration path for users --> No ## References <!-- Please list any other resources or points the reviewer should be aware of --> remix-run/remix#8891 rollup/rollup#4699
Reproduction
If I got more time, I may submit a PR with a failing test, but for now, here’s an issue.
To reproduce:
System Info
Used Package Manager
pnpm
Expected Behavior
Build output should be short. Vite should not complain about
"use client"
directive.Note that there is a similar issue in another project.
use client
directive with Vite TanStack/query#5175Based on the above issue,
@vitejs/plugin-react
should suppress this error for us. However, it seems that Remix’svitePlugin
does not come with Vite’s React plugin and implements its own React support.Perhaps Remix’s Vite plugin should add the warning silencer just like
@vitejs/plugin-react
? The warning silencer seems to implemented here: https://github.com/vitejs/vite-plugin-react/blob/814ed8043d321f4b4679a9f4a781d1ed14f185e4/packages/plugin-react/src/index.ts#L303-L319Actual Behavior
I get a wall of warning in the build output that looks like this:
The text was updated successfully, but these errors were encountered: