From 15024336731b588fb4815d42ef439b92a9eebdcf Mon Sep 17 00:00:00 2001 From: Sean Sanker Date: Wed, 8 May 2024 06:45:46 -0400 Subject: [PATCH] fix(vite): don't generate tasks for remix projects (#22551) ## Current Behavior Attempting to use Remix + Vite results in a few errors. I assume this is due to the vite and remix plugins conflicting with each other. One of which being: ``` Failed to process project graph. The "@nx/vite/plugin" plugin threw an error while creating nodes from myremixapp/vite.config.ts: Error: Missing "root" route file in /Users/username/work/remix-demo/app at Object.resolveConfig (/Users/username/work/remix-demo/node_modules/@remix-run/dev/dist/config.js:154:11) at updateRemixPluginContext (/Users/username/work/remix-demo/node_modules/@remix-run/dev/dist/vite/plugin.js:367:9) at config (/Users/username/work/remix-demo/node_modules/@remix-run/dev/dist/vite/plugin.js:598:7) ``` ## Expected Behavior It should work just like it currently does for Remix Classic. ## Related Issue(s) #22035 ## PR Status This is a very early draft. I don't think this is a good approach but it does work for me at the moment. I'm not sure exactly how we can discern a remix project from a vanilla vite project (that you can use standard tooling for) without parsing the `package.json` or `vite.config.ts` and searching for remix-specific content. ## Steps to reproduce my current state Set up a standard @nx/remix project as shown [here](https://nx.dev/recipes/react/remix). Follow the instructions [here](https://remix.run/docs/en/main/future/vite#migrating) from `Migrating` down to but NOT including `Migrating a custom server`. Once I use the modified @nx/vite code provided in this PR, I'm able to run `npx nx dev [app-name]` successfully. ## A Personal Note I'd love to contribute more to nrwl/nx. I'm quite a fan of Nx and use it in a few separate projects. That being said, I don't currently have a comprehensive knowledge of its internals. If anyone wants to give me some guidance (text-based or we can hop on a call), I'd be more than happy to contribute the rest of this myself (and other fixes). --------- Co-authored-by: Colum Ferry --- packages/vite/src/plugins/plugin.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/vite/src/plugins/plugin.ts b/packages/vite/src/plugins/plugin.ts index 1e34eb37a5..0147066d19 100644 --- a/packages/vite/src/plugins/plugin.ts +++ b/packages/vite/src/plugins/plugin.ts @@ -127,7 +127,13 @@ async function buildViteTargets( const targets: Record = {}; // If file is not vitest.config and buildable, create targets for build, serve, preview and serve-static - if (!configFilePath.includes('vitest.config') && isBuildable) { + const hasRemixPlugin = + viteConfig.plugins && viteConfig.plugins.some((p) => p.name === 'remix'); + if ( + !configFilePath.includes('vitest.config') && + !hasRemixPlugin && + isBuildable + ) { targets[options.buildTargetName] = await buildTarget( options.buildTargetName, namedInputs,