GithubHelp home page GithubHelp logo

Comments (25)

schickling avatar schickling commented on May 26, 2024 12

Can you try adding dom to your libs array?

Example:

{
  "compilerOptions": {
    "target": "es5",
    "moduleResolution": "node",
    "module": "commonjs",
    "sourceMap": true,
    "noUnusedLocals": true,
    "rootDir": "src",
    "outDir": "dist",
    "lib": [
      "dom"
    ]
  }
}

from graphql-request.

ngocdaothanh avatar ngocdaothanh commented on May 26, 2024 9

For completeness, there are other errors:

node_modules/graphql-request/dist/src/index.d.ts:11:18 - error TS2304: Cannot find name 'Headers'.

11         headers: Headers;
                    ~~~~~~~

node_modules/graphql-request/dist/src/index.d.ts:22:14 - error TS2304: Cannot find name 'Headers'.

22     headers: Headers;
                ~~~~~~~

node_modules/graphql-request/dist/src/types.d.ts:8:14 - error TS2304: Cannot find name 'RequestInit'.

8     method?: RequestInit['method'];
               ~~~~~~~~~~~

node_modules/graphql-request/dist/src/types.d.ts:10:12 - error TS2304: Cannot find name 'RequestInit'.

10     mode?: RequestInit['mode'];
              ~~~~~~~~~~~

node_modules/graphql-request/dist/src/types.d.ts:11:19 - error TS2304: Cannot find name 'RequestInit'.

11     credentials?: RequestInit['credentials'];
                     ~~~~~~~~~~~

node_modules/graphql-request/dist/src/types.d.ts:12:13 - error TS2304: Cannot find name 'RequestInit'.

12     cache?: RequestInit['cache'];
               ~~~~~~~~~~~

node_modules/graphql-request/dist/src/types.d.ts:13:16 - error TS2304: Cannot find name 'RequestInit'.

13     redirect?: RequestInit['redirect'];
                  ~~~~~~~~~~~

node_modules/graphql-request/dist/src/types.d.ts:14:16 - error TS2304: Cannot find name 'RequestInit'.

14     referrer?: RequestInit['referrer'];
                  ~~~~~~~~~~~

node_modules/graphql-request/dist/src/types.d.ts:15:22 - error TS2304: Cannot find name 'RequestInit'.

15     referrerPolicy?: RequestInit['referrerPolicy'];
                        ~~~~~~~~~~~

node_modules/graphql-request/dist/src/types.d.ts:16:17 - error TS2304: Cannot find name 'RequestInit'.

16     integrity?: RequestInit['integrity'];
                   ~~~~~~~~~~~


Found 10 errors.

from graphql-request.

lednhatkhanh avatar lednhatkhanh commented on May 26, 2024 7

You should not include a dom lib to an api project, it may leads to some weird behaviors.

from graphql-request.

 avatar commented on May 26, 2024 4

fetch is normally a DOM-only API -- this package appears to have an API similar to fetch, but not the same. It's used like:

export interface Options {
    method?: RequestInit['method'];
    headers?: Headers;
    mode?: RequestInit['mode'];
    credentials?: RequestInit['credentials'];
    cache?: RequestInit['cache'];
    redirect?: RequestInit['redirect'];
    referrer?: RequestInit['referrer'];
    referrerPolicy?: RequestInit['referrerPolicy'];
    integrity?: RequestInit['integrity'];
}

Maybe the best solution would be to just copy the relevant parts instead of referencing RequestInit. There's also microsoft/TypeScript#15780 which would allow you to pull in dom typings without users needing to modify tsconfig.json, but that then adds a bunch of globals that they might not need.

from graphql-request.

kallaspriit avatar kallaspriit commented on May 26, 2024 4

Why was this closed? I'm using graphql-request for testing graphql with Jest in a nodejs API application and I don't really want to include dom as lib in tsconfig.json.

from graphql-request.

brikou avatar brikou commented on May 26, 2024 3

One quick workaround is to update tsconfig.json:

{
    "compilerOptions": {
        "skipLibCheck": true,
    }
}

I believe your TS compilation will also be faster.

from graphql-request.

schmod avatar schmod commented on May 26, 2024 3

Can a maintainer please look at one of the two PRs open that addresses this issue?

from graphql-request.

kbrandwijk avatar kbrandwijk commented on May 26, 2024

Unable to reproduce in the current version.

from graphql-request.

maxdarque avatar maxdarque commented on May 26, 2024

I get this in when I run tsc on "graphql-request": "^1.4.0",

from graphql-request.

maxdarque avatar maxdarque commented on May 26, 2024

@schickling thanks that works

from graphql-request.

schickling avatar schickling commented on May 26, 2024

@lednhatkhanh while I haven't seen any issues with this yet, do you have any other suggestions? Using fetch in TypeScript is definitely weird in general in regards to type definitions.

cc @andy-ms @RyanCavanaugh

from graphql-request.

divyenduz avatar divyenduz commented on May 26, 2024

With the latest version - 1.7.0 I ran only into error TS2304: Cannot find name 'AsyncIterable'. in node_modules/@types/graphql/subscription/subscribe.d.ts

from graphql-request.

maxdarque avatar maxdarque commented on May 26, 2024

@divyenduz are you including esnext.asynciterable under the tsconfig.json lib option?

{
  "compilerOptions": {
    "target": "es2017",
    "lib": [ "es2017", "dom", "esnext.asynciterable" ],
    "moduleResolution": "node",
    "module": "commonjs",
    "sourceMap": true,
    "rootDirs": ["src", "stress-tests"],
    "outDir": "dist",
    "removeComments": true,
    "strictNullChecks": false,
    "noUnusedLocals": false,
    "noUnusedParameters": false
  }
}

from graphql-request.

divyenduz avatar divyenduz commented on May 26, 2024

Nope, to test this out I used the following (empty) tsconfig.json

{}

from graphql-request.

maxdarque avatar maxdarque commented on May 26, 2024

I don't quite follow. So have you tried adding esnext.asynciterable to the tsconfig.json lib option?

from graphql-request.

divyenduz avatar divyenduz commented on May 26, 2024

Ah! got it now, yes it works with esnext.asynciterable. The idea was to make it work without any additions to tsconfig.json but this won't be possible for AsyncIterable because the dep is in graphql-js. Thanks!

from graphql-request.

divyenduz avatar divyenduz commented on May 26, 2024

@kallaspriit : Thanks for the feedback, reopened. Do you suggest that we extract the required parts from dom lib into the source code itself? Can you come up with a PR for this to see how that looks like? Thanks!

from graphql-request.

kallaspriit avatar kallaspriit commented on May 26, 2024

I gave it a go and managed to remove the dom lib dependency by including the required types along with the library. Can't also use the @types/fetch-mock as it depends on dom lib as well.

Hope it helps :)

from graphql-request.

schickling avatar schickling commented on May 26, 2024

🎉 This issue has been resolved in version 2.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

from graphql-request.

jasonkuhrt avatar jasonkuhrt commented on May 26, 2024

Unfortunately this issue is not resolved yet.

If the consumer sets their compilerOptions.lib property and it doesn't include dom then this issue will occur.

from graphql-request.

jasonkuhrt avatar jasonkuhrt commented on May 26, 2024

I just tried a solution based on the types given by @kallaspriit in #100 and that is working ok.

from graphql-request.

MarkLyck avatar MarkLyck commented on May 26, 2024

I'm having this issue on version 3.3.0

running in a node environment where I have no possibility to change the tsconfig file, so the 2 suggested solutions are not possible.

from graphql-request.

jasonkuhrt avatar jasonkuhrt commented on May 26, 2024

@MarkLyck can you share exactly what your issue is? This is a long and old thread.

from graphql-request.

MarkLyck avatar MarkLyck commented on May 26, 2024

@jasonkuhrt same error as the author: "Cannot find name RequestInit"

I'm running this in a node environment (there is no "Dom") and I don't have control over the tsconfig. So I cannot set typescript to ignore lib or add the Dom to it.

Looking at the index.d.ts it is directly referencing Dom types, which don't exist in Node. So the errors make sense, but I can't "work around it" like the suggested solutions as I don't have control over the exact modules or typescript configuration.

from graphql-request.

jasonkuhrt avatar jasonkuhrt commented on May 26, 2024

@MarkLyck What version of lib the are you using? The Dom imports you see are inlined and not actually the relying on the global environment.

from graphql-request.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.