最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Unable to set up the new Faker library - Stack Overflow

programmeradmin4浏览0评论

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:

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/[email protected]/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 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:

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/[email protected]/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

Share Improve this question edited Jan 13, 2022 at 13:49 Alex Ironside asked Jan 13, 2022 at 13:37 Alex IronsideAlex Ironside 5,07914 gold badges76 silver badges134 bronze badges 3
  • I believe import faker from 'faker' in your code (not in the .d.ts file!) should be import faker from '@faker-js/faker'. – CherryDT Commented Jan 13, 2022 at 14:05
  • That does not work for me atleast. – bhordupur Commented Jan 27, 2022 at 14:54
  • I didn't find a solution. – Alex Ironside Commented Jan 28, 2022 at 12:56
Add a ment  | 

4 Answers 4

Reset to default 4

I created a sample project: https://stackblitz./edit/faker-js-demo-b16k2u?file=index.ts
I may link it into our README.md if needed (I'm one of the maintainers of @faker-js/faker

发布评论

评论列表(0)

  1. 暂无评论