#Migrate legacy React app to Remix Vite with ESM: dev server working but prod failing

1 messages · Page 1 of 1 (latest)

fair mason
#

Hello everyone,

I've migrated our ~7 year old react app to remix. The current production version uses the express template with non-vite remix v2.7.0.

I'm now trying to get the app migrated to vite. I followed the instructions in https://remix.run/docs/en/main/guides/vite#migrating. After several attempts I thought I finally had it working using vite-plugin-cjs-interop (edit: I initially wrongly said vite-tsconfig-paths). That is, until I tried to deploy to our staging environment and it failed.

This app uses a very old version of redux-saga v0.16.2 (yes, I know I'll have to fix/remove this 😅 )

The dev server (i.e. yarn dev) is working but when running with the prod build (yarn build; yarn start) it fails with:

$ cross-env NODE_ENV=production node ./server.js
node:internal/modules/run_main:129
    triggerUncaughtException(
    ^

Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory import '/Users/username/poc/remix/remix-vite-express2/node_modules/redux-saga/effects' is not supported resolving ES modules imported from /Users/username/poc/remix/remix-vite-express2/build/server/index.js
Did you mean to import "redux-saga/lib/effects.js"?
    at finalizeResolution (node:internal/modules/esm/resolve:259:11)
    ...
  code: 'ERR_UNSUPPORTED_DIR_IMPORT',
  url: 'file:///Users/username/poc/remix/remix-vite-express2/node_modules/redux-saga/effects'
}

Node.js v20.14.0
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

You can reproduce this by running:

npx create-remix@latest --template remix-run/remix/templates/express
yarn add [email protected]

Then update app/routes/_index.tsx to import the something from redux-saga/effects and reference it

 import type { MetaFunction } from "@remix-run/node";
+import { takeLatest } from "redux-saga/effects";

...

 export default function Index() {
+  console.log(takeLatest);
   return (

....

Anyone have any pointers?

fair mason
#

Still not sure why there would be difference between the dev and prod build. I made the required changes to upgrade to the latest version of redux-saga. That version works without needing vite-plugin-cjs-interop

raw fog
#

I started off following the Remix docs, and my express server was created and started by using node ./server.js but by doing this that server.js file and anything it imports is not getting compiled by Vite. By uing the above plugin you can have your local and production exress serer file be compiled by Vite which would allow vite-plugin-cjs-interop and the rest of your vite config to do it's thing