minifaker icon indicating copy to clipboard operation
minifaker copied to clipboard

Importing localsccurs

Open ma7ma7 opened this issue 3 years ago • 5 comments

Hello,

When we try importing locals an error

import 'minifaker/locales/en';

An error occurs in this example I used parcel

@parcel/core: Failed to resolve 'minifaker/locales/en' from './src/index.js'

My solution was importing the locals directaly:

import '../node_modules/minifaker/dist/esm/locales/en';

I think is better to define a default local or add a method to set the locals

minifaker.setLocal('en');

Thank you man 🙏

ma7ma7 avatar Jan 14 '22 19:01 ma7ma7

I found in the type a setDefaultLocale() but doesn't work, is better to update the documentation please.

ma7ma7 avatar Jan 14 '22 19:01 ma7ma7

hmmm I don't think parcel support conditionnal exports https://nodejs.org/api/packages.html#conditional-exports I could be wrong though

In the mean time you can use

import 'minifaker/dist/esm/locales/en'

You don't have to use setDefaultLocale()

g45t345rt avatar Jan 14 '22 20:01 g45t345rt

Yeah, the import as you mention is working fine, I wish that if you found some time to update the documentation is gonna be great.

Thank you a lot man

ma7ma7 avatar Jan 14 '22 22:01 ma7ma7

I also found the similar problem when using minifaker in jest tests.

CleanShot 2565-01-16 at 00 25 24@2x

Solved by adding this line in jest.config.js

transformIgnorePatterns: ['node_modules/(?!minifaker)']

And this line into compilerOptions in tsconfig.spec.json

"allowJs": true

Not sure if it was related to this issue or not?

earthpyy avatar Jan 15 '22 17:01 earthpyy

I also have this problem when running e2e tests on NestJs and that didn't fix it for me.

Vanderscycle avatar Jan 18 '22 20:01 Vanderscycle