A
A
aris-paskalov2021-12-28 15:11:49
typescript
aris-paskalov, 2021-12-28 15:11:49

Why can't I import the faker module?

I'm writing TypeScript code, I need random data, so I decided to use the Faker package

Installed it like this:

npm i --save-dev @types/faker

61cafebda3a08867632844.png

This is how I import it into my project:

61cafedf89d16562673417.png

But the following error pops up in the console:

61cafefe991f3063094053.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Aetae, 2021-12-28
@aris-paskalov

In order for packages to be loaded from node_modules by name, the script must be run in node (i.e. on the server), or collected by a collector (which will pick it up by name and pack it into a script).
If you want to use them directly in the browser via type moule, you will have to explicitly specify specific paths to specific script files with your hands. package.jsonand everything connected with it is the node ecosystem. Because of its convenience and versatility, it is accepted as the standard for all front development, but the browser knows nothing about it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question