Closed bronifty closed 1 year ago
It looks like mdx plugin is transpiling JSX into jsxDEV(...)
instead of jsx(...)
even for build command.
I tested your reproduction and setting mdx plugin's development
option explicitly seems to solve the issue:
export default defineConfig((env) => ({
plugins: [
...
mdx({
development: env.command === "serve", /// <==== switch based on `vite dev` or `vite build`
remarkPlugins: [
remarkFrontmatter,
remarkMdxFrontmatter,
],
})
],
}));
If this is not handled by mdx
plugin itself, maybe it's worth mentioning in remix doc https://remix.run/docs/en/main/future/vite#add-mdx-plugin
EDIT: I realized that mdx plugin is a rollup plugin and thus not dedicated as a vite plugin, so it seems configuring development
option is vite user's responsibility https://mdxjs.com/packages/rollup/#options.
EDIT2: Investigating further, it looks like rollup plugin actually infers development
option based on mode
https://github.com/mdx-js/mdx/blob/efff74e48aec9286c62185bf04f7b8aa72e07bd6/packages/rollup/lib/index.js#L79, so I would feel user-side explicit configuration is not necessarily for normal case.
The reason why this is not working might be because of some inconsistency with viteChildCompiler
used by remix...?
EDIT3: Confirming the above assumption by debugging with this plugin:
function debugPlugin(): Plugin {
let count = 0;
return {
name: "debug",
config(_config, env) {
console.log("[debug:config]", ++count, env);
},
buildEnd() {
console.log("[debug:buildEnd]", count);
},
}
}
This will show following logs:
I think simply copying "plugin objects" to child vite server can lead to some plugin hooks called in an unexpected way since it's common to save some state in "plugin factory" closure.
(Alternative would be reading vite.config.ts
again for child compiler so that "plugin instances" are independent...?)
At least, it probably makes sense to pass same mode
to child compiler so that it won't confuse plugins like mdx rollup plugin which makes use of mode
. (EDIT: created a PR https://github.com/remix-run/remix/pull/7911)
it was tough following this thread but I checked the file you changed in the PR and it works thanks
Sorry about my comment derailing a bit too much... Thanks for testing and providing the reproduction!
no problem thank you!
Fixed by #7911.
What version of Remix are you using?
2.2.0
Are all your remix dependencies & dev-dependencies using the same version?
Steps to Reproduce
use remix as a vite plugin, build an app with a tsx route that consumes mdx via the @mdx-js/rollup plugin and build. head to the mdx consumer route and it breaks with the error message TypeError: t.jsxDEV is not a function at o (http://localhost:3000/build/assets/test-1a250893.js:9:223) at l (http://localhost:3000/build/assets/test-1a250893.js:10:578) at io (http://localhost:3000/build/assets/entry.client-1dd82fdc.js:68:19477) at ja (http://localhost:3000/build/assets/entry.client-1dd82fdc.js:70:43691) at Da (http://localhost:3000/build/assets/entry.client-1dd82fdc.js:70:39496) at id (http://localhost:3000/build/assets/entry.client-1dd82fdc.js:70:39427) at $r (http://localhost:3000/build/assets/entry.client-1dd82fdc.js:70:39287) at Ni (http://localhost:3000/build/assets/entry.client-1dd82fdc.js:70:35709) at Ta (http://localhost:3000/build/assets/entry.client-1dd82fdc.js:70:34665) at E (http://localhost:3000/build/assets/entry.client-1dd82fdc.js:55:1562)
Expected Behavior
i expect it to not break
Actual Behavior
it breaks. here's the repo to repro: https://github.com/bronifty/migrate-remix-to-vite.git