Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cjs: Importing specific locale in jest test fails with 'Cannot find module' #462

Closed
shmuelsochet opened this issue Feb 10, 2022 · 8 comments · Fixed by #520
Closed

cjs: Importing specific locale in jest test fails with 'Cannot find module' #462

shmuelsochet opened this issue Feb 10, 2022 · 8 comments · Fixed by #520
Labels
c: bug Something isn't working

Comments

@shmuelsochet
Copy link

Describe the bug

When importing specific locale during a jest test, the test fails with the error Cannot find module '@faker-js/faker/locale/en' from...

Reproduction

  1. Add the line const faker = require('@faker-js/faker/locale/en'); on top of a jest file (i.e example.test.js)
  2. Run test `npm run test example.test.js
  3. You should get the 'Cannot find module '@faker-js/faker/locale/en' error

Additional Info

This does not occur when using the same import not during a jest test.
It also does not occur when not using specific locale like this const { faker } = require('@faker-js/faker');

@shmuelsochet shmuelsochet added the s: pending triage Pending Triage label Feb 10, 2022
@Shinigami92
Copy link
Member

Can you try to provide a reproducible via https://stackblitz.com/edit/faker-js-demo?file=index.ts ?
Or maybe just a minimal GitHub repo

@import-brain import-brain added question Further information is requested s: awaiting more info Additional information are requested and removed s: pending triage Pending Triage question Further information is requested labels Feb 10, 2022
@hansonfang
Copy link

I have same issue after I upgraded it to 6.0.0 alpha. so I downgraded to 5.5.3 than problems gone.

@Shinigami92
Copy link
Member

I have same issue after I upgraded it to 6.0.0 alpha. so I downgraded to 5.5.3 than problems gone.

We are still missing a minimal reproduction, so maybe you could provide one?

@Shinigami92 Shinigami92 added c: bug Something isn't working and removed s: awaiting more info Additional information are requested labels Feb 19, 2022
@Shinigami92 Shinigami92 changed the title Importing specific locale in jest test fails with 'Cannot find module' cjs: Importing specific locale in jest test fails with 'Cannot find module' Feb 19, 2022
@Shinigami92 Shinigami92 linked a pull request Feb 19, 2022 that will close this issue
@Shinigami92
Copy link
Member

@shmuelsochet @hansonfang Please try out the alpha.7 and report if the issue is fixed for you

@rich-frost
Copy link

We've noticed this issue again in version 8 when running our jest tests; error as follows:

Test suite failed to run

    Cannot find module '@faker-js/faker/locale/en' from 'node_modules/our-module/main.js

Have downgraded to version 7 and it works. Is this something that can be looked at in version 8?

@matthewmayer
Copy link
Contributor

matthewmayer commented Oct 20, 2023

Can you switch to the prepackaged faker instances available in v8 eg

const { fakerEN : faker } = require('@faker-js/faker');

@rich-frost
Copy link

We have a legacy project that bundles this into the built code (work in progress to extract) so we were looking to just bring in the EN locale to reduce bundle size

@ST-DDT
Copy link
Member

ST-DDT commented Oct 20, 2023

We've noticed this issue again in version 8 when running our jest tests; error as follows:

Test suite failed to run

    Cannot find module '@faker-js/faker/locale/en' from 'node_modules/our-module/main.js

Have downgraded to version 7 and it works. Is this something that can be looked at in version 8?

This issue is closed and I'm unable to reproduce the error locally.

const { faker } = require("@faker-js/faker/locale/en");
console.log(typeof faker); // object
console.log(faker.person.firstName()); // Tatyana
console.log(faker.location.city()); // Fisherborough

Please create a new issue and provide a minimal reproducible example.

@faker-js faker-js locked as resolved and limited conversation to collaborators Oct 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
c: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants