cross-fetch icon indicating copy to clipboard operation
cross-fetch copied to clipboard

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

Open wiesson opened this issue 4 years ago • 9 comments

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)

wiesson avatar Mar 31 '21 12:03 wiesson

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

pbeyeler avatar Mar 31 '21 13:03 pbeyeler

@wiesson can you share your tsconfig?

lquixada avatar Mar 31 '21 15:03 lquixada

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

wiesson avatar Mar 31 '21 15:03 wiesson

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?

eps1lon avatar Apr 01 '21 09:04 eps1lon

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.

Vadorequest avatar Apr 01 '21 15:04 Vadorequest

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.

lquixada avatar Apr 01 '21 15:04 lquixada

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

  "resolutions": {
    "cross-fetch": "3.1.4-alpha.0"
  }

Vadorequest avatar Apr 01 '21 16:04 Vadorequest

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

Vinnl avatar Apr 01 '21 19:04 Vinnl

just released 3.1.4

lquixada avatar Apr 02 '21 23:04 lquixada