Unable to import faker locale sub package in React app (react-scripts v4)

94 views Asked by At

According to faker docs, it is encouraged to import individual locales using the following syntax (to avoid loading full 5Mb faker bundle):

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

However, after running yarn add @faker-js/faker, the app won't build and I get this error:

Module not found: Can't resolve '@faker-js/faker/locale/de' in (...)

It works fine if I do

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

However, I lose the benefit of a reduced bundle size.

It seems like this is due to the way exports are configured in faker's package.json. They are not supported in webpack 4, however, in order to upgrade to webpack 5, I would also need to migrate my entire React app to react-scripts v5, which contains a lot of breaking changes.

So, is there an alternate way of importing individual locales, while keeping the faker bundle size down and without upgrading react-scripts ?

0

There are 0 answers