All jobs

Migrate a Create React App Project to Vite

Yes. An agent swaps react-scripts for Vite and Vitest, fixes what the swap breaks in a React 16 app, and opens a pull request with the build and tests passing.

Run this on RushOpens the console with this prompt ready to send, in a Project that has your repository.

What the agent does

The agent starts by writing down what works today, because an old Create React App project often cannot build on a current Node at all. In a project like the-road-to-learn-react/hackernews-client, package.json pins react-scripts 3.1.0 with React ^16.8.4, and package-lock.json is still lockfileVersion 1 with React locked at 16.8.4. On Node 22, npm test passes nine tests with four snapshots, while npm run build stops with error:0308010C:digital envelope routines::unsupported, raised from webpack 4's createHash. With NODE_OPTIONS=--openssl-legacy-provider the old build compiles, so the agent uses that once to record what build/ contains before it changes anything.

Then it makes the swap and works through the failures in the order they appear. Installing vite, @vitejs/plugin-react, vitest and jsdom stops with ERESOLVE: react-addons-test-utils 15.6.2 sits in devDependencies, no file imports it, and it asks for react-dom ^15.4.2. The agent removes it. It moves public/index.html to the repository root, drops the two %PUBLIC_URL% prefixes and adds a module script tag for the entry. The first build fails at src/index.js:7 with Unexpected JSX expression, since Vite parses JSX only in .jsx and .tsx files, so src/index.js, src/App.js and src/App.test.js are renamed. The second build fails to resolve react/jsx-runtime: the plugin compiles to the automatic JSX runtime, which React 16.8.4 does not ship. Raising react, react-dom and react-test-renderer to 16.14.0 stays inside the declared range and adds that entry point, and the agent prefers it to a React major upgrade in the same pull request.

Some things build and are still wrong, and the agent looks for them. src/index.js contains if (module.hot) { module.hot.accept(); }, a webpack API. Vite's dev server serves that line unchanged, and a browser ES module has no module object, so the agent deletes it; Fast Refresh comes from the plugin. It sets build.outDir to build, because .gitignore and any deploy script expect that directory and Vite's default is dist. It names the config vite.config.mjs, since package.json has no "type": "module" and Vite 8 warns about ESM syntax in a .js config. The eslintConfig block extends react-app, a config that came with react-scripts and ran inside the webpack build, so removing the package also removes linting. The agent states that in the pull request and does not replace it silently.

Tests move to Vitest with environment: 'jsdom' and globals: true; without the second setting the file fails with ReferenceError: describe is not defined. All nine tests run, Enzyme adapter included. The snapshots need care: Vitest looks for src/__snapshots__/App.test.jsx.snap, ignores the Jest file beside it, writes each key as App > has a valid snapshot 1 and prints { where Jest printed Object {. With CI=true it writes nothing and the four snapshot tests fail as mismatched. The agent generates the new file, diffs it against the old one to show that only those two notations differ, and deletes the Jest file.

Start it with one API call

POST https://api.phoenix.so/o/{org}/sessions with this body:

{
  "agent": "claude",
  "input": "Migrate this Create React App project from react-scripts to Vite, and its tests from Jest to Vitest. First record the baseline: run npm ci, npm test and npm run build on the installed Node and keep the output. If the build fails with a digital envelope routines error, build once with NODE_OPTIONS=--openssl-legacy-provider and list the files in build/ as the reference. Then remove react-scripts and add vite, @vitejs/plugin-react, vitest and jsdom. If npm reports ERESOLVE, find the package that causes it, check whether any file imports it, and say what you did. Move public/index.html to the root, remove every %PUBLIC_URL%, add the module script tag, and rename every file that contains JSX to .jsx. If the plugin needs react/jsx-runtime and the locked React does not have it, raise React within the range package.json already declares; do not change the React major. Search src for module.hot, process.env and REACT_APP_ and fix each use for Vite. Keep the output directory named build. If the app calls serviceWorker.register(), stop and ask before choosing a replacement; if it only calls unregister(), keep that call. Configure Vitest with jsdom, run the existing tests unchanged, regenerate the snapshot file, and show a diff proving the old and new snapshots differ only in notation. Update the scripts in package.json and any CI file so npm test exits on its own. Do not rewrite components or tests beyond what the migration needs. Open a pull request with the output of every command, a before and after listing of build/, and a list of anything react-scripts did that Vite no longer does.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
  1. Get an API key. In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
  2. Send the request. POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
  3. Read what came back. Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

What comes back

A pull request that removes react-scripts and react-addons-test-utils from package.json, adds the four new packages, rewrites package-lock.json, moves index.html, renames the three JSX files and their snapshot, adds vite.config.mjs, and changes the start, build and test scripts while dropping eject. The description gives the baseline first: the test summary and the build error on the unchanged repository. After that it lists each failure met during the swap with the change that resolved it, the final vite build output and the Vitest summary.

It closes with a section on what no longer happens. The webpack build wrote service-worker.js and a precache-manifest file into build/ even though the app only calls serviceWorker.unregister(); the Vite build writes neither. Hashed files move from build/static/js and build/static/css to build/assets. ESLint no longer runs during the build. The browserslist field is no longer what decides the output syntax.

A reviewer checks three things before merging. The snapshot diff should show only renamed keys and the Object { prefix removed, since a regenerated snapshot can hide a real change. The React bump to 16.14.0 should be the only version change that is not part of the tooling swap. And anything that serves the app should be checked against the new file layout, since a cache rule or a server path written for static/ will not match assets/.

Run it on every repository still on react-scripts

This is a one-time job for each repository, so the event is a developer deciding to do it. Send the body to POST /o/{org}/sessions from a terminal or an MCP client, with a request_id that is a UUID made once for the job, and carry on with other work. If the run ends on a question, such as whether to keep the Enzyme tests or which Node version CI should use, a follow-up to POST /o/{org}/sessions/{id}/messages wakes the same sandbox with node_modules already installed.

A team with several Create React App repositories sends the same body once for each from a script, each with a request_id that is a UUID v5 of the repository's full name so a rerun of the script starts nothing twice. Runs past the key's concurrency limit are created as queued and start as slots free, and a webhook_url on the key receives run.completed for each run that key started.

The use case this job follows, with its automation and trigger: Hand off a long task.

Why run it on Rush?

The work is a chain of failures where each fix reveals the next one: a peer dependency conflict, then a JSX parse error, then a missing runtime entry point, then snapshots that do not match. None of them is hard, and every one costs an install or a build to find. In its own sandbox the agent runs that loop to the end without holding anyone's attention, and the transcript at GET /o/{org}/sessions/{id}/messages keeps every command with its output, so the pull request's account of what broke can be checked line by line.

It also starts from a clean machine, which is the honest test for a project this old. A laptop that has built the app for years has a Node version manager, a global flag or a cached node_modules that hides the fact that a fresh clone no longer builds. The sandbox has none of that, so the baseline in the pull request is what a new contributor or a CI runner would see.

Frequently asked questions

Do I have to rename every .js file to .jsx?

Only the files that contain JSX. Vite decides how to parse a file from its extension, so a .js file with a JSX tag fails at the first tag. Files without JSX, such as src/serviceWorker.js here, keep their names. The agent finds the files by attempting the build and by searching, and the rename shows in the pull request as a move, so history follows the file.

Will my REACT_APP_ environment variables still work?

Not under that name. Vite exposes variables that start with VITE_ on import.meta.env, and process.env.REACT_APP_X is no longer replaced at build time. The agent searches for both patterns and rewrites each use, and lists the variables your hosting or CI settings need renamed. The fixture this page was written against has none, which the search confirms.

Does the migration require upgrading React?

Only as far as 16.14.0, and only when the lockfile holds an older 16.x. The React plugin's default output imports react/jsx-runtime, which arrived in that release. The plugin also accepts jsxRuntime: 'classic' for a project that must stay on an exact older version. Moving to React 18 or 19 is a separate pull request with its own risks.

Why do the snapshot tests fail in CI right after the switch?

Because Vitest names the snapshot file after the renamed test file and formats keys and objects differently from Jest, so it finds no stored snapshot to compare with. Locally it would write new ones; with CI=true it reports a mismatch. The fix is to commit the regenerated file in the same pull request, after checking that it differs from the old one only in notation.

What happens to the service worker?

The old build generated a Workbox service worker file whether or not the app registered it. Vite generates none. An app that calls unregister(), like this one, loses nothing. An app that calls register() needs a decision, usually a PWA plugin for Vite or dropping offline support, and the agent stops to ask before choosing one.

More Create React App jobs

More jobs like this: Hand off a long task

Keep reading