Comments (25)
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.
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.
You should not include a dom lib to an api project, it may leads to some weird behaviors.
from graphql-request.
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.
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.
One quick workaround is to update tsconfig.json:
{
"compilerOptions": {
"skipLibCheck": true,
}
}
I believe your TS compilation will also be faster.
from graphql-request.
Can a maintainer please look at one of the two PRs open that addresses this issue?
from graphql-request.
Unable to reproduce in the current version.
from graphql-request.
I get this in when I run tsc
on "graphql-request": "^1.4.0",
from graphql-request.
@schickling thanks that works
from graphql-request.
@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.
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.
@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.
Nope, to test this out I used the following (empty) tsconfig.json
{}
from graphql-request.
I don't quite follow. So have you tried adding esnext.asynciterable
to the tsconfig.json lib option?
from graphql-request.
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.
@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.
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.
🎉 This issue has been resolved in version 2.0.0 🎉
The release is available on:
Your semantic-release bot 📦🚀
from graphql-request.
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.
I just tried a solution based on the types given by @kallaspriit in #100 and that is working ok.
from graphql-request.
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.
@MarkLyck can you share exactly what your issue is? This is a long and old thread.
from graphql-request.
@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.
@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)
- Cannot find module 'graphql-request/build/esm/types' or its corresponding type declarations.ts HOT 10
- Extension to bring back file upload support
- How do get the IP address of the client in the request middleware?
- I want the GraphQLClient instance to return response headers along with data HOT 2
- Include a new option to ignore operationName to avoid parsing for extraction. HOT 1
- How to pass headers while using `getServerSideProps` HOT 1
- Image Upload HOT 1
- Dynamic Headers: use async function to get headers HOT 2
- TypeError: response.headers.forEach is not a function HOT 1
- `client.request()` does not take a `signal` option as shown in examples HOT 2
- Invalid execution result: data is not plain object HOT 6
- ts-client custom scalars
- Support passing relative path for URL HOT 7
- Variables typing gives unexpected error HOT 1
- `TypeError: Only absolute URLs are supported` when testing with jsdom. HOT 2
- Link to custom fetch function in README.md is not working
- Prevent request in request middleware and return some cached response
- Access request options in responseMiddleware HOT 3
- Add request headers to a client error in a response middleware HOT 3
- Memoizing fetch error: Body is unusable
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from graphql-request.