Skip to content

Unable to set up the new Faker library

I am trying to set up the new @faker-js/faker library. So far, I did this:

npm i @faker-js/faker -D

Added faker.d.ts at the top level. So the tree is like this:

enter image description here

faker.d.ts contents is this:

// faker.d.ts
declare module '@faker-js/faker' {
  import faker from 'faker';
  export default faker;

I am trying to use the mock like this:

import faker from 'faker';

import { ParameterMessage } from 'packages/ts/container/Parameter';

export const Parameter: ParameterMessage = { id: faker.dataType.uuid };

But am keep getting an error, saying

Cannot find module ‘faker’ or its corresponding type declarations.ts(2307)

Unable to resolve path to module ‘faker’.

I am also getting this in faker.d.ts

File ‘/home/aironside@ant.local/Documents/microfrontends/telegram-manager/src/faker.d.ts’ is not a module.

When hovering over ‘faker’ in import faker from 'faker';

What am I missing?

Here is a reproduced sandbox


I created a sample project:
I may link it into our if needed (I’m one of the maintainers of @faker-js/faker 🙂)