Skip to content
On this page

Upgrading to v8

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

Since v8 has not yet been released, this is a work in progress list of any major and breaking changes in v8.

INFO

Not the version you are looking for?

Breaking changes

Removed ability to change the locale on existing Faker instances

NOTE

If you are using only the default (en) locale, then you don't have to change anything.

In order to facilitate better and easier locale fallback mechanics, we removed the methods to change the locales on existing Faker instances. Now, we expose specific faker instances for each locale that you can use:

Old

ts
import { faker } from '@faker-js/faker';

faker.setLocale('de_CH');
// or
faker.locale = 'de_CH';
faker.fallbackLocale = 'en';

New

ts
import { fakerDE_CH as faker } from '@faker-js/faker';

This also fixes issues where more than two locales are required:

Old

ts
import { faker } from '@faker-js/faker';

const customFaker = new Faker({
  locale: 'de_CH', // the expected locale
  fallbackLocale: 'de', // ensure we have a German fallbacks for addresses
  locales: { de_CH, de, en },
});
const a = customFaker.internet.email();
customFaker.locale = 'en'; // neither 'de_CH' nor 'de' have emojis
const b = customFaker.internet.emoji();

New

ts
import { Faker, de_CH, de, en, base } from '@faker-js/faker';

// same as fakerDE_CH
export const customFaker = new Faker({
  // Now multiple fallbacks are supported
  locale: [de_CH, de, en, base],
});
const a = customFaker.internet.email();
const b = customFaker.internet.emoji();

If you wish to create entries for multiple locales, you can still do so:

Old

ts
import { faker } from '@faker-js/faker';

for (let user of users) {
  const lang = faker.helpers.arrayElement(['de', 'en', 'fr']);
  faker.locale = lang;
  user.email = faker.internet.email();
}

New

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

for (let user of users) {
  const currentFaker = faker.helpers.arrayElement([fakerDE, fakerEN, fakerFR]);
  user.email = currentFaker.internet.email();
}

For more information refer to our Localization Guide.

faker.mersenne and faker.helpers.repeatString removed

faker.mersenne and faker.helpers.repeatString were only ever intended for internal use, and are no longer available.

Other deprecated methods removed/replaced

Old methodNew method
faker.uniquefaker.helpers.unique
faker.fakefaker.helpers.fake
faker.commerce.colorfaker.color.human
faker.company.companyNamefaker.company.name
faker.phone.phoneNumberfaker.phone.number
faker.phone.phoneNumberFormatNo direct replacement, see documentation for faker.phone.number
faker.phone.phoneFormatsNo direct replacement, see documentation for faker.phone.number
faker.name.findNameRemoved, replace with faker.person.fullName
faker.address.cityPrefixRemoved
faker.address.citySuffixRemoved
faker.address.streetPrefixRemoved
faker.address.streetSuffixRemoved
faker.image.lorempixelRemoved, as the LoremPixel service is no longer available

Locale renamed

The en_IND (English, India) locale was renamed to en_IN for consistency with other locales.

Deprecations and other changes

faker.name changed to faker.person

The whole faker.name module is now located at faker.person, as it contains more information than just names. The faker.name.* methods will continue to work as an alias in v8 and v9, but it is recommended to change to faker.person.*

Old methodNew method
faker.name.firstNamefaker.person.firstName
faker.name.lastNamefaker.person.lastName
faker.name.middleNamefaker.person.middleName
faker.name.fullNamefaker.person.fullName
faker.name.genderfaker.person.gender
faker.name.sexfaker.person.sex
faker.name.sexTypefaker.person.sexType
faker.name.prefixfaker.person.prefix
faker.name.suffixfaker.person.suffix
faker.name.jobTitlefaker.person.jobTitle
faker.name.jobDescriptorfaker.person.jobDescriptor
faker.name.jobAreafaker.person.jobArea
faker.name.jobTypefaker.person.jobType
faker.name.findNameRemoved, replace with faker.person.fullName

faker.address changed to faker.location

The whole faker.address module is now located at faker.location, as it contains more information than just addresses. The faker.address.* methods will continue to work as an alias in v8 and v9, but it is recommended to change to faker.location.*

Old methodNew method
faker.address.buildingNumberfaker.location.buildingNumber
faker.address.cardinalDirectionfaker.location.cardinalDirection
faker.address.cityfaker.location.city
faker.address.cityNamefaker.location.cityName
faker.address.countryfaker.location.country
faker.address.countryCodefaker.location.countryCode
faker.address.countyfaker.location.county
faker.address.directionfaker.location.direction
faker.address.fakerfaker.location.faker
faker.address.latitudefaker.location.latitude
faker.address.longitudefaker.location.longitude
faker.address.nearbyGPSCoordinatefaker.location.nearbyGPSCoordinate
faker.address.ordinalDirectionfaker.location.ordinalDirection
faker.address.secondaryAddressfaker.location.secondaryAddress
faker.address.statefaker.location.state
faker.address.stateAbbrfaker.location.stateAbbr
faker.address.streetfaker.location.street
faker.address.streetAddressfaker.location.streetAddress
faker.address.streetNamefaker.location.streetName
faker.address.timeZonefaker.location.timeZone
faker.address.zipCodefaker.location.zipCode
faker.address.zipCodeByStatefaker.location.zipCodeByState
faker.address.cityPrefixRemoved
faker.address.citySuffixRemoved
faker.address.streetPrefixRemoved
faker.address.streetSuffixRemoved

Number methods of faker.datatype moved to new faker.number module

The number-related methods previously found in faker.datatype have been moved to a new faker.number module. For the old faker.datatype.number method you should replace with faker.number.int or faker.number.float depending on the precision required.

By default, faker.number.float no longer defaults to a precision of 0.01

js
// OLD
faker.datatype.number({ max: 100 }); // 35
faker.datatype.number({ max: 100, precision: 0.01 }); // 35.21
faker.datatype.float({ max: 100 }); // 35.21
faker.datatype.float({ max: 100, precision: 0.001 }); // 35.211

// NEW
faker.number.int({ max: 100 }); // 35
faker.number.float({ max: 100 }); // 35.21092065742612
faker.number.float({ max: 100, precision: 0.01 }); // 35.21
Old methodNew method
faker.datatype.numberfaker.number.int or faker.number.float
faker.datatype.floatfaker.number.float
faker.datatype.bigIntfaker.number.bigInt

Deprecation of faker.datatype.array

The method faker.datatype.array has been deprecated and will be removed in v9. If you need an array of useful values, you are better off creating your own one using faker.helpers.multiple.

allowLeadingZeros behavior change in faker.string.numeric

The allowLeadingZeros boolean parameter in faker.string.numeric (in the new string module) now defaults to true. faker.string.numeric will now generate numeric strings that could have leading zeros by default.

Simplified MIME type data

The functions faker.system.mimeType, faker.system.fileType and faker.system.fileExt now return data from a smaller set of more common MIME types, filetypes and extensions.

Released under the MIT License.