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

Types are not found when using node with ESM and typescript@4.7.2 with NodeNext #1004

Closed
julienfouilhe opened this issue May 25, 2022 · 4 comments · Fixed by #1005
Closed
Labels
c: bug Something isn't working p: 1-normal Nothing urgent s: accepted Accepted feature / Confirmed bug

Comments

@julienfouilhe
Copy link
Contributor

julienfouilhe commented May 25, 2022

Describe the bug

Yesterday Typescript released a new version (4.7.2) that adds ESM support for Nodejs 16+ (see their release announcement).

faker is broken when using it, here is the error:

Could not find a declaration file for module '@faker-js/faker'. '/Users/julien/cash/cash/node_modules/@faker-js/faker/dist/esm/index.mjs' implicitly has an 'any' type.
  Try `npm i --save-dev @types/faker-js__faker` if it exists or add a new declaration (.d.ts) file containing `declare module '@faker-js/faker';`

1 import { faker } from "@faker-js/faker";

I upgraded to 7.0.0 and it was fixed, but 7.0.1 reverts the fix (PR here), I couldn't find the reason for that anywhere.

Reproduction

Minimal repro is available here: https://github.com/julienfouilhe/faker-node-next-ts-repo with steps to reproduce available in the README.

Additional Info

7.0.0 fixes the issue.

@julienfouilhe julienfouilhe added the s: pending triage Pending Triage label May 25, 2022
@Shinigami92
Copy link
Member

I couldn't find the reason for that anywhere

The issue was that TypeScript compatibility without using NodeNext fully broke
So we need to find a way that works with AND without using that

@Shinigami92 Shinigami92 moved this to Todo in Faker Roadmap May 25, 2022
@Shinigami92 Shinigami92 added this to the v7 - Current Major milestone May 25, 2022
@Shinigami92 Shinigami92 added c: bug Something isn't working p: 1-normal Nothing urgent s: accepted Accepted feature / Confirmed bug and removed s: pending triage Pending Triage labels May 25, 2022
@Shinigami92
Copy link
Member

Okay I'm confused, I don't understand why "types": "index.d.ts" is needed. If I change that the cjs version is broken.
So actually it was maybe my fault in 371aeb8 and I'm sorry about that.

I now restructured the https://github.com/faker-js/playground and added a ts 4.7 nodenext playground!
And your initial PR without changing the "types" field is working...
I will try to reopen your initial PR so you get the commit credits

@Shinigami92
Copy link
Member

Nevermind, cannot reopen a merged PR... would you like to re-create the PR? (just to get the credits)

@Shinigami92 Shinigami92 moved this from Todo to In Progress in Faker Roadmap May 25, 2022
@Shinigami92
Copy link
Member

It just needs to be

  "exports": {
    ".": {
      "types": "./dist/types/index.d.ts",
      "require": "./dist/cjs/index.js",
      "import": "./dist/esm/index.mjs"
    },
    "./locale/*": {
      "types": "./dist/types/locale/*.d.ts",
      "require": "./dist/cjs/locale/*.js",
      "import": "./dist/esm/locale/*.mjs"
    },
    "./package.json": "./package.json"
  },

Repository owner moved this from In Progress to Done in Faker Roadmap May 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: bug Something isn't working p: 1-normal Nothing urgent s: accepted Accepted feature / Confirmed bug
Projects
No open projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants