lquixada / cross-fetch

Universal WHATWG Fetch API for Node, Browsers and React Native.
MIT License
1.67k stars 104 forks source link

[Typescript] DOM libs are undefined (v3.1.2) #104

Closed wiesson closed 1 year ago

wiesson commented 3 years ago

When installing cross-fetch v3.1.3, it somehow overrides the typescript settings. Despite having dom in lib in the tsconfig, Typescript starts to complain about e.g. window and URLSearchParams. If I downgrade to v3.1.2, it does not happen. Maybe you have an idea, why cross-fetch somehow overrides "everything" (?)

I'm using it with nextjs (latest version)

pbeyeler commented 3 years ago

We're having the exact same problem. Would be great if this could be solved as soon as possible.

lquixada commented 3 years ago

@wiesson can you share your tsconfig?

wiesson commented 3 years ago

Sure!

{
  "compilerOptions": {
    "target": "ES2020",
    "lib": ["dom", "dom.iterable", "esnext"],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": false,
    "forceConsistentCasingInFileNames": true,
    "noEmit": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve",
    "baseUrl": "src",
    "paths": {
      "@/components/*": ["components/*"],
      "@/lib/*": ["lib/*"],
      "@/utils/*": ["utils/*"],
      "@/types/*": ["types/*"]
    }
  },
  "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
  "exclude": ["node_modules"]
}

it is more or less the default tsconfig of Nextjs

eps1lon commented 3 years ago

Possibly caused by https://github.com/lquixada/cross-fetch/commit/f3b2fc48fb57ffaeabd9f2f9e598b76cb511831b which added no-default-lib triple slash directives. Once I remove that directive from my local typings, everything is back to normal. The directive will instruct TypeScript to not include their lib.d.ts.

I've never seen this directive used in library typings so I can't say what this commit tried to solve. Maybe @lquixada has some insight?

Vadorequest commented 3 years ago

This is breaking the faunadb library as well.

At this point, my whole project is unusable, is there a workaround (like a smart edit of the yarn.lock to force using the previous version?)

https://github.com/fauna/faunadb-js/issues/459

And I can concur about the triple slash directive, it's what causing the issue.

lquixada commented 3 years ago

hey all! sorry for the trouble! adding local types to cross-fetch has been trickier than originally thought so I'm reverting those changes so everyone can run it safely. Please let me know if 3.1.4-alpha.0 works for you.

Vadorequest commented 3 years ago

For anyone affected by this, you can add the following to package.json:

  "resolutions": {
    "cross-fetch": "3.1.4-alpha.0"
  }
Vinnl commented 3 years ago

@lquixada I can confirm that it fixes it for my project!

lquixada commented 3 years ago

just released 3.1.4