# Migrate From faker to @faker-js/faker in a Node.js Project

Yes. An agent replaces the abandoned faker package with @faker-js/faker, renames every moved method, fixes the Node version in CI and runs the tests.

[Run this on Rush](https://cloud.getrush.ai/run/migrate-faker-to-faker-js/faker/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The npm package `faker` stopped being usable upstream: its `latest` tag points at 6.6.6, a release with 8 files where 5.5.3 had 1,793. The maintained library is `@faker-js/faker`. The agent reads what the project pins and where the calls are. In a tool like ngduc/api-now, `package.json` asks for `faker ^4.1.0` and `yarn.lock` resolves 4.1.0, so the empty release cannot be installed by accident. One file requires it, `tests/generateData.js`, with 14 calls of seven kinds. Despite its folder that file is runtime code: `lib/server.js` serves it as the default dataset and `lib/routes/apolloServer.js` loads it when the GraphQL route is built.

The agent installs the new package and tries each old call against it before editing, so the pull request can say exactly what broke. With `@faker-js/faker` 10.6.0, `faker.lorem.sentence()` and `faker.image.avatar()` still work. The other five throw a `TypeError`. `faker.name` and `faker.random` no longer exist, and `faker.date.between('2018-01-01', '2019-12-31')` fails because the function now takes one object. The replacements are `faker.person.fullName()`, `faker.person.lastName()`, `faker.string.uuid()`, `faker.number.int({ min, max })` and `faker.date.between({ from, to })`, and the import becomes `const { faker } = require('@faker-js/faker')`.

Changing only the `require` line gives a misleading test result, which the agent records. All 12 Jest tests fail, each after about five seconds, including the ones that serve a plain JSON file and never touch fake data. The server process loads the dataset at startup for the GraphQL route, throws there and never opens its port, so every test times out waiting for it. After the five renames the same 12 pass.

The remaining work is outside the source file. Version 10 is published as an ES module only and its `engines` field asks for Node `^20.19.0 || ^22.13.0 || ^23.5.0 || >=24.0.0`, while `.github/workflows/nodejs.yml` tests on Node 8, 10 and 12. No major of the new package reaches back that far: 9.9.0 needs Node 18 and 7.6.0 needs 14. The agent raises the matrix to releases the chosen version supports and says so first in the description, since that is a change to who can run the tool.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "Replace the npm package faker with @faker-js/faker in this project. Read package.json and the lockfile to see which faker version is resolved, find every file that requires or imports it, and list each distinct call (for example name.findName, random.uuid, random.number, date.between, image.avatar). Install with the lockfile and run the tests before changing anything. Add @faker-js/faker and remove faker using the package manager the lockfile belongs to. Before editing source, run each old call against the new package in a small script and record which ones throw and with what message. Then update the import to the named faker export and rename each call to its current equivalent (person.fullName, person.lastName, string.uuid, number.int, date.between with a from and to object), keeping every generated field's meaning the same. Read the new package's engines field and its module type, compare them with the Node versions in the CI workflow and the engines field of this project, and update the CI matrix if they do not overlap; say which Node versions lose support. Run the tests again, start the application once and show a sample of the generated data. Update any README example that uses the old package name. Open a pull request with the call table, the commands and their output.",
  "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 edits `tests/generateData.js`, `package.json`, `yarn.lock`, the CI workflow and the README line that tells users to write data files with faker. The description opens with the Node version change, then gives the call table: seven old calls, the result of each on the new package, and its replacement. The test runs follow: 12 passing before, 12 timing out with only the import changed, 12 passing after.

Two details are left for the reviewer to judge. The dataset fills `firstName` with `name.findName()`, which returns a full name; the port keeps that with `person.fullName()` and points it out without changing the data's shape. And avatars change host. The old library returned an address under `s3.amazonaws.com/uifaces`, which now answers 403, and the new one returns a jsDelivr address. Anything that stored the old addresses keeps them; only newly generated rows differ.

## Run it on every repository that still depends on faker

This is a one-time job per repository, so a script suits it better than a standing trigger. List your repositories whose `package.json` names `faker`, and for each one send this body to `POST /o/{org}/sessions` with its URL in `resources`. Add a `request_id` that is a UUID v5 of the repository name, so running the script again returns the run already started instead of opening a second pull request.

A key runs `max_concurrent` sessions at a time and the rest answer `202` with `status: "queued"`, so the script needs no pacing of its own. Collect results from `GET /o/{org}/sessions`, or from the `run.completed` webhook if the key has a `webhook_url`.

## Why run it on Rush?

The rename table is easy to find online; what a team lacks is the evidence for its own code. Here that means running every old call against the new package, seeing the whole suite time out for a reason unrelated to most tests, and learning that the CI matrix cannot install the dependency at all. The agent does each of those in a sandbox with the project's lockfile and keeps the output, so the pull request explains failures a reviewer would otherwise rediscover.

Repeating it across many repositories is the other reason. Each run gets its own machine, installs that repository's dependencies and reports that repository's calls, and the runs do not wait on one another beyond the key's concurrency limit.

## Frequently asked questions

### Which faker methods were renamed?

In this project: `name.findName` to `person.fullName`, `name.lastName` to `person.lastName`, `random.uuid` to `string.uuid`, `random.number` to `number.int`, and `date.between` now takes `{ from, to }`. `lorem.sentence` and `image.avatar` kept their names. The agent builds the table from your own calls and tests each one.

### Can I still use require() with @faker-js/faker?

On a recent Node, yes. Version 10 ships as an ES module only, and `require` of it works on the Node releases its `engines` field lists, which can load an ES module synchronously. On older runtimes use version 9, which the registry lists as needing Node 18 or later, or switch the file to `import`.

### Why did every test fail after I changed only the import?

Because the data file runs at server startup. One throwing call stops the process before it listens, and each test then waits for a port that never opens. The failure looks like a timeout in unrelated tests, which is why the agent probes the calls directly first.

### Is the old faker package dangerous to keep?

A pinned 4.x or 5.x release keeps installing and working, and a caret range on 4 or 5 cannot select 6.6.6. The reasons to move are that nothing is fixed there any more and that the data it generates ages, as the dead avatar addresses show.

## More jobs like this: Upgrade dependencies weekly

- [Migrate From Flask-Cache to Flask-Caching](https://getrush.ai/run/migrate-flask-cache-to-flask-caching/flask-cache/)
- [Migrate From Flask-JWT to Flask-JWT-Extended](https://getrush.ai/run/migrate-flask-jwt-to-flask-jwt-extended/flask-jwt/)
- [Migrate From Flask-RESTPlus to Flask-RESTX](https://getrush.ai/run/migrate-flask-restplus-to-flask-restx/flask-restplus/)
- [Migrate From Flask-Script to the Flask CLI](https://getrush.ai/run/migrate-flask-script-to-flask-cli/flask-script/)
- [Migrate From garyburd/redigo to gomodule/redigo](https://getrush.ai/run/migrate-garyburd-redigo-to-gomodule-redigo/redigo/)
- [Migrate a Go Test Suite From Ginkgo v1 to Ginkgo v2](https://getrush.ai/run/migrate-ginkgo-v1-to-v2/ginkgo/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
