Skip to content

Upgrading to v9

This is the migration guide for upgrading from v8 to v9.

Not the version you are looking for?

v9 has not yet been released. This page contains a work-in-progress list of breaking changes in v9.

General Breaking Changes

Requires Node v18+

Support for Node.js v14 and v16 has been discontinued as these versions have reached their end-of-life. Faker.js v9 requires a minimum of Node.js v18.

Upgrade to TypeScript v5

We now use TypeScript v5 for our project (previously v4). While generally not breaking for users, this might have small side effects on our types.

Usage of TypeScript 5 Features

The helpers module now uses TS5 features, so if you are using Faker with TypeScript, you must use TS5.

// v8
faker.helpers.arrayElement([1, 2, 3]); // number
faker.helpers.arrayElement([1, 2, 3] as const); // 1 | 2 | 3

// v9
faker.helpers.arrayElement([1, 2, 3]); // 1 | 2 | 3

Fix Tree Shaking

Prior to this version, there was an issue where all locales would be bundled even if only one was used. Users had to resort to a workaround by importing specific faker instances from dedicated paths.

import { faker } from '@faker-js/faker/locale/de';

With this fix, the workaround should no longer be necessary. You will be able to import different localized faker instances from the root of your package with the bundle only including those specific locales.

import { fakerDE, fakerES, fakerFR } from '@faker-js/faker';

The dedicated import paths are kept in v9, to allow a gradual migration for our users.

While this is not a breaking change according to semantic versioning guidelines, it does impact the behavior of users' bundlers.

Use High Precision RNG by Default

TLDR: Many Faker methods return a different result in v9 compared to v8 for the same seed.

In v9 we switch from a 32 bit random value to a 53 bit random value. We don't change the underlying algorithm much, but we now consume two seed values each step instead of one. This affects generated values in two ways:

  • In large lists or long numbers the values are spread more evenly. This also reduces the number of duplicates it generates. For this reduces the number of duplicates from 1 / 10_000 to less than 1 / 8_000_000.
  • If you start with the same initial seed to generate a value, you might see some changes in the results you get. This is because we're now working with a higher precision, which affects how numbers are rounded off. As a result, the methods we use might produce slightly different outcomes. And since we are now using two seed values each time subsequent results appear to skip a value each time.
import {
} from '@faker-js/faker';

// < v9 default
const f32 = new SimpleFaker({ randomizer: generateMersenne32Randomizer() });
const r32 = f32.helpers.multiple(() =>, { count: 10 });
// > v9 default
const f53 = new SimpleFaker({ randomizer: generateMersenne53Randomizer() });
const r53 = f53.helpers.multiple(() =>, { count: 5 });

diff(r32, r53);
//  7,
//  7,
//  3,
//  4,
//  2,
//  7,
//  6,
//  7,
//  7,
//  5,


  • If you don't have any seeded tests and just want some random values, then you don't have to change anything.
  • If you have seeded tests, you have to update most test snapshots or similar comparisons to new values.
  • If you are using vitest, you can do that using pnpm vitest run -u.

Keeping the Old Behavior

You can keep the old behavior, if you create your own Faker instance and pass a Randomizer instance from the generateMersenne32Randomizer() function to it.

import {
  generateMersenne32Randomizer, // < v9 default
  generateMersenne53Randomizer, // > v9 default
} from '@faker-js/faker';

const faker = new Faker({
  randomizer: generateMersenne32Randomizer(),

Using tsup for the Build Process

After the switch to tsup, the dist folder now contains minified and chunked files for CJS. However, as we officially support only exports defined via package.json, this should not affect your code.

Removals of Deprecated Code

A large number of methods which were deprecated in v8 are completely removed in v9. To prepare for the upgrade, it is recommended to first upgrade to the latest version of v8 (e.g. npm install --save-dev faker@8) and fix any deprecation warnings issued by your code.

The following sections contain more information about these changes.

Constructor and JS Backwards-Compatibility Methods

Removed deprecated faker constructor, so you can no longer just pass a locale string identifier.

Also removed the accessors and method that were only for JS backwards compatibility.

  • get/set locales
  • get/set locale
  • get/set localeFallback
  • setLocale

To use the new constructor, you need to pass a locale object like:

import { Faker, es, base } from '@faker-js/faker';

// A custom faker instance that does not have any fallbacks
const customEsFakerWithoutFallback = new Faker({ locale: es });

// A custom faker instance that has only base-data as fallback, but not english data
const customEsFakerWithFallback = new Faker({ locale: [es, base] });

Commerce Module

Removed deprecated commerce methods

faker.commerce.price(min, max, dec, symbol)faker.commerce.price({ min, max, dec, symbol })

Company Module

Removed deprecated company methods

oldreplacement of of

Company Name Affix files reorganized

The company name affix files have been used inconsistently. Sometimes suffixes were used as prefixes in the patterns, because they contained legal entity types (and in English these were defined as suffixes). We renamed the files to match their actual content instead of their hypothetical position. If you are using the public methods, no changes are required. You only need to change your code if you are accessing the raw definitions e.g. in faker.helpers.fake().


Note: In some locales prefixes and suffixes might have been swapped, so the mapping might be wrong for those.

Datatype Module

Removed deprecated datatype methods

faker.datatype.number() or faker.number.float()
faker.datatype.datetime({ min, max }){ from, to }) or
faker.datatype.hexadecimal()faker.string.hexadecimal() or faker.number.hex()
faker.datatype.json()your own function to generate complex objects
faker.datatype.array()your own function to build complex arrays

Date Module

Removed deprecated date methods

oldreplacement, refDate){ years, refDate }), refDate){ years, refDate }), to){ from, to }), to, count){ from, to, count }), refDate){ days, refDate }), refDate){ days, refDate }){ abbr }){ abbreviated }){ abbr }){ abbreviated })

Finance Module

Removed deprecated finance methods

oldreplacement, max, dec, symbol, autoFormat){ min, max, dec, symbol, autoFormat }), countryCode){ formatted, countryCode })

Git Module

Removed deprecated git methods

faker.git.shortSha()faker.git.commitSha({ length: 7 })

Helpers Module

Removed deprecated helpers methods

faker.helpers.replaceSymbolWithNumberstring.replace(/#+/g, (m) => faker.string.numeric(m.length))
faker.helpers.uniqueimport { UniqueEnforcer } from 'enforce-unique';

Note these are not exact replacements:


The replaceSymbolWithNumber method was deprecated in Faker v8.4 and removed in v9.0. The method parsed the given string symbol by symbol and replaces the # symbol with digits (0 - 9) and the ! symbol with digits >=2 (2 - 9). This was primarily used internally by Faker for generating phone numbers. If needed, you can use a simple string replace combined with faker.string.numeric to replace this

// old
faker.helpers.replaceSymbolWithNumber('#####-##'); // '04812-67'

// new
'#####-##'.replace(/#+/g, (m) => faker.string.numeric(m.length));

// old
faker.helpers.replaceSymbolWithNumber('!#####'); // '123152'

// new
  .replace(/#+/g, (m) => faker.string.numeric(m.length))
  .replace(/!+/g, (m) =>
    faker.string.numeric({ length: m.length, exclude: ['0', '1'] })


The regexpStyleStringParse method in faker.helpers was deprecated in Faker v8.1 and removed in v9.0. A likely replacement is the more powerful faker.helpers.fromRegExp.

faker.helpers.regexpStyleStringParse('a{3,6}'); // aaaaa
faker.helpers.fromRegExp('a{3,6}'); // aaaaa

However, please note that faker.helpers.fromRegExp is not an exact replacement for faker.helpers.regexpStyleStringParse as fromRegExp cannot handle numeric ranges. This now needs to be handled separately.

faker.helpers.regexpStyleStringParse('a{3,6}[1-100]'); // "aaaa53", etc.
faker.helpers.fromRegExp('a{3,6}') +{ min: 1, max: 100 });


Prior to v9, Faker provided a faker.helpers.unique() method which had a global store to keep track of duplicates. This was removed in v9.

Please see the unique values guide for alternatives.

For example, many simple use cases can use faker.helpers.uniqueArray. Or you can migrate to a recommended third party package such as enforce-unique:

Basic example:

// OLD
const name = faker.helpers.unique(faker.person.firstName);

// NEW
import { UniqueEnforcer } from 'enforce-unique';
//const { UniqueEnforcer } = require("enforce-unique") // CJS

const enforcerName = new UniqueEnforcer();
const name = enforcerName.enforce(faker.person.firstName);

With parameters:

// OLD
const stateCode = faker.helpers.unique(faker.location.state, [
    abbreviated: true,

// NEW
import { UniqueEnforcer } from 'enforce-unique';

const enforcerState = new UniqueEnforcer();
const stateCode = enforcerState.enforce(() =>
    abbreviated: true,

With options:

// OLD
const city = faker.helpers.unique(, [], {
  maxRetries: 100,
  maxTime: 1000,

// NEW
import { UniqueEnforcer } from 'enforce-unique';

const enforcer = new UniqueEnforcer();
const city = enforcer.enforce(, {
  maxRetries: 100,
  maxTime: 1000,


enforce-unique does not directly support the store option previously available in faker.helpers.unique. If you were previously using this parameter, check the documentation. If you need to reset the store, you can call the reset() method on the UniqueEnforcer instance.

faker.helpers.arrayElement and faker.helpers.arrayElements

The following only affects usage in Javascript, as in Typescript this usage would already throw a compile-time error.

Previously, the arrayElement and arrayElements methods would throw a dedicated error, when called without arguments.

faker.helpers.arrayElement(undefined); // FakerError: Calling `faker.helpers.arrayElement()` without arguments is no longer supported.

Now, it throws a JS native error:

faker.helpers.arrayElement(undefined); // TypeError: Cannot read properties of undefined (reading 'length')

Calling the methods with an empty array instead still behaves as before.

Image Module

Removed deprecated image methods

faker.image.abstract()faker.image.urlLoremFlickr({ category: 'abstract' }) or faker.image.url()
faker.image.animals()faker.image.urlLoremFlickr({ category: 'animals' }) or faker.image.url(){ category: 'business' }) or faker.image.url()
faker.image.cats()faker.image.urlLoremFlickr({ category: 'cats' }) or faker.image.url(){ category: 'city' }) or faker.image.url(){ category: 'food' }) or faker.image.url()
faker.image.nightlife()faker.image.urlLoremFlickr({ category: 'nightlife' }) or faker.image.url(){ category: 'fashion' }) or faker.image.url()
faker.image.people()faker.image.urlLoremFlickr({ category: 'people' }) or faker.image.url()
faker.image.nature()faker.image.urlLoremFlickr({ category: 'nature' }) or faker.image.url()
faker.image.sports()faker.image.urlLoremFlickr({ category: 'sports' }) or faker.image.url()
faker.image.technics()faker.image.urlLoremFlickr({ category: 'technics' }) or faker.image.url()
faker.image.transport()faker.image.urlLoremFlickr({ category: 'transport' }) or faker.image.url()

Image Providers

Removed deprecated image providers from faker.image. They already returned broken image URLs anyway.

faker.image.lorempicsum.imageGrayscalefaker.image.urlPicsumPhotos({ grayscale: true })
faker.image.lorempicsum.imageBlurredfaker.image.urlPicsumPhotos({ blur: 4 })
faker.image.unsplash.foodfaker.image.urlLoremFlickr({ category: 'food' })
faker.image.unsplash.peoplefaker.image.urlLoremFlickr({ category: 'people' })
faker.image.unsplash.naturefaker.image.urlLoremFlickr({ category: 'nature' })
faker.image.unsplash.technologyfaker.image.urlLoremFlickr({ category: 'technology' })
faker.image.unsplash.objectsfaker.image.urlLoremFlickr({ category: 'objects' })
faker.image.unsplash.buildingsfaker.image.urlLoremFlickr({ category: 'buildings' })

Internet Module

Removed deprecated internet methods

faker.internet.avatar()faker.image.avatarLegacy() or faker.image.avatar(), lastName, provider, options){ firstName, lastName, provider, ... })
faker.internet.exampleEmail(firstName, lastName, options)faker.internet.exampleEmail({ firstName, lastName, ... })
faker.internet.userName(firstName, lastName)faker.internet.userName({ firstName, lastName })
faker.internet.displayName(firstName, lastName)faker.internet.displayName({ firstName, lastName })
faker.internet.color(redBase, greenBase, blueBase)faker.internet.color({ redBase, greenBase, blueBase })
faker.internet.password(length, memorable, pattern, prefix)faker.internet.password({ length, memorable, pattern, prefix })

Location Module

Removed deprecated location methods

faker.location.zipCodeByStatefaker.location.zipCode({ state })
faker.location.stateAbbr()faker.location.state({ abbreviated: true })
faker.location.latitude(max, min, precision)faker.location.latitude({ max, min, precision })
faker.location.longitude(max, min, precision)faker.location.longitude({ max, min, precision })
faker.location.direction(abbreviated)faker.location.direction({ abbreviated })
faker.location.cardinalDirection(abbreviated)faker.location.cardinalDirection({ abbreviated })
faker.location.ordinalDirection(abbreviated)faker.location.ordinalDirection({ abbreviated })
faker.location.nearbyGPSCoordinate(coordinate, radius, isMetric)faker.location.nearbyGPSCoordinate({ origin, radius, isMetric })

Direction definitions reorganized

The locale definitions used by faker.location.direction(), faker.location.cardinalDirection() and faker.location.ordinalDirection() have been reorganized. Previously, they were located under definitions.location.direction and definitions.location.direction_abbr and their values were required to be in a specific order. Now, all values are nested under definitions.location.direction with descriptive property names. If you are using the public methods, no changes are required. You only need to change your code if you are accessing the raw definitions e.g. in faker.helpers.fake().

location.directionlocation.direction.cardinal or location.direction.ordinal
location.direction_abbrlocation.direction.cardinal_abbr or location.direction.ordinal_abbr

Default country definitions removed

The faker.definitions.location.default_country definition has been removed, as they were not used by any public method, and were not useful for locales which don't correspond directly to a single country, like ar.

Number Module

Removed deprecated number parameter

faker.number.float({ precision })faker.number.float({ multipleOf })

Person Module

Changed Definitions

The locale definitions used by faker.person.jobTitle(), faker.person.jobDescriptor(), faker.person.jobArea() and faker.person.jobType() have been reorganized and are no longer nested under definitions.person.title. Conversely, the gendered locale definitions used by faker.person.firstName(), faker.person.lastName(), faker.person.middleName() and faker.person.prefix() are now consolidated under a single definition property. If you are using the public methods, no changes are required. You only need to change your code if you are accessing the raw definitions e.g. in faker.helpers.fake().


Phone Module

Removed deprecated phone methods

oldreplacement, faker.string.numeric() or faker.helpers.fromRegExp()

Random Module

Removed deprecated random module

faker.random.word()faker.lorem.word() or faker.word.sample()
faker.random.words()faker.lorem.words() or faker.word.words()

Locale Aliases

Renamed deprecated locale aliases cz, en_IND, ge and removed global.

import { faker } from '@faker-js/faker/locale/cz'import { faker } from '@faker-js/faker/locale/cs_CZ'
import { faker } from '@faker-js/faker/locale/en_IND'import { faker } from '@faker-js/faker/locale/en_IN'
import { faker } from '@faker-js/faker/locale/ge'import { faker } from '@faker-js/faker/locale/ka_GE'
import { faker } from '@faker-js/faker/locale/global'import { faker } from '@faker-js/faker/locale/base'

Renamed Locale Definitions

The following locale definitions have been adjusted to align with Faker's locale definition naming standard:


With that now all our locale data use the following naming scheme:


Please keep in mind that property keys of complex objects remain in camel-case.


Type Aliases

Removed deprecated type aliases


Breaking Changes to Specific Methods

Birthdate New Default Mode

Previously, the method had defaults that were unclear in their specific impact. Now, the method requires either none or all of the min, max and mode options.

We also improved the error messages in case of invalid min/max age/year ranges.

Fail on Invalid Dates

Various methods in the module allow you to pass a Date-ish value: that is, either a Javascript Date, or a timestamp number or string that can be converted to a Date via the new Date() constructor.

Previously, if you passed something which could not be parsed to a Date, it would fall back to the current reference date. Now, this throws an error raising awareness of that bad value.

This affects the refDate parameter of the anytime(), birthdate(), past(), future(), recent() and soon(), methods as well as the from and to parameters of between() and betweens().

Separate Timezone Methods

The timeZone functionality has been divided to enhance specificity:

  • Use to generate a random global time zone.
  • Use faker.location.timeZone() to obtain time zone specific to the current locale.

We haven't updated all locale dependent time zone data yet, so if you encounter unexpected values, please create a new issue.

Prices Now Return More Price-Like Values

The faker.commerce.price() method now produces values that also return fractional values.

Old price: 828.00 New price: 828.59

The last digit of the price is adjusted to be more price-like:

  • 50% of the time: 9
  • 30% of the time: 5
  • 10% of the time: 0
  • 10% of the time: a random digit from 0 to 9

We plan to rethink this method some more in the future: #2579

Images Have Random Options by Default

faker.image.url() now returns an image url with a random width and height by default. To obtain the previous behavior, pass {width: 640, height: 480}.

faker.image.urlLoremFlickr() now returns an image url with a random width and height by default. To obtain the previous behavior, pass {width: 640, height: 480}.

faker.image.urlPicsumPhotos() now returns an image url with a random width and height by default, additionally images may be converted to grayscale and blurred at random. To obtain the previous behavior, pass {width: 640, height: 480, blur: 0, grayscale: false}

faker.image.dataUri() now returns an image url with a random width and height by default, additionally the type of the image is now random. To obtain the previous behavior, pass {width: 640, height: 480, type: 'svg-uri'}.

Require from and to in and betweens

Previously, in and if the from or to parameter was omitted (in Javascript) or an invalid date (in Javascript or Typescript), they would default to the current date or reference date. Now, both boundaries must be given explicitly. If you still need the old behavior, you can pass or the reference date for from or to.

Stricter Checking for Function Signature Passed to faker.helpers.multiple Method

The faker.helpers.multiple method takes a function reference as its first parameter. Previously you may have written code like this to generate multiple values.

faker.helpers.multiple(, { count: 2 });

However this code has a bug - faker.helpers.multiple passes the loop index as the second parameter to the method, which in this case would set the refDate of the call to 0, making all dates before 1970.

Instead you should generally use a lambda function like

faker.helpers.multiple(() =>, { count: 2 });

to get the desired behavior. In v9.0, we use stricter type-checking in Typescript to detect when a function is called which is not compatible with (v: unknown, index: number) which can cause compile-time errors in places where previously there were potential runtime errors.


faker.helpers.multiple(faker.person.firstName, ...); // ❗
// In Typescript, this is now a compile time error
// Argument of type '(sex?: "female" | "male" | undefined) => string'
// is not assignable to parameter of type '(v: unknown, index: number) => unknown'.


faker.helpers.multiple(() => faker.person.firstName(), ...); // ✔

The new types also allow for easier use-cases where the index is part of the generated data e.g. as id.

faker.helpers.multiple((_, index) => ({ id: index, ...}), ...); // [{id: 0, ...}, ...]

Stricter Enum Value Usage

Some methods would previously fallback to a default value for an option when an unknown value was passed for a enum parameter. Now, these methods return undefined instead. This only affects usage in Javascript, as in Typescript this usage would already throw a compile-time error.

For example:

faker.color.rgb({ format: 'unexpectedvalue' });
// in Faker v8, is [110, 82, 190] like { format: "decimal" }
// in Faker v9, is undefined

This affects:

  • The format property of faker.color.rgb() must be one of 'binary' | 'css' | 'decimal' | 'hex' if provided
  • The format property of faker.color.cmyk(), faker.color.hsl(), faker.color.hwb(), faker.color.lab(), faker.color.lch() must be one of 'binary' | 'css' | 'decimal' if provided
  • The variant property of faker.location.countryCode() must be one of alpha-2, alpha-3, numeric if provided
  • The casing property of faker.string.alpha() and faker.string.alphanumeric() must be one of 'upper' | 'lower' | 'mixed' if provided

Phone Number style Replaces Explicit format generates a phone number for the current locale. Previously, there was little control over the generated number, which may or may not have included country codes, extensions, white space, and punctuation.

If you wanted more control over the number, it was previously necessary to pass an explicit format parameter. This has now been removed. Instead, you can consider one of two options:

  1. The new style parameter has convenient options for common use cases. There are three possible values.
    • 'human': (default, existing behavior) A human-input phone number, e.g. 555-770-7727 or 555.770.7727 x1234
    • 'national': A phone number in a standardized national format, e.g. (555) 123-4567.
    • 'international': A phone number in a E.123 standard international format with country code, e.g. +15551234567

The styles are locale-aware, so for example if you use pt_PT, phone numbers suitable for Portugal would be generated.

  1. If none of the styles match your needs, you can use faker.string.numeric() or faker.helpers.fromRegExp() to create a custom pattern.

Released under the MIT License.