dotansimha / dotansimha/graphql-code-generator
Typescript 4.7 & Node16 ModuleResolution compilation errors.
- Dominant language
- TypeScript
- Stars
- 11.3k
- Forks
- 1.4k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 23
Description
### Issue workflow progress
_Progress of the issue based on the [Contributor Workflow](https://github.com/the-guild-org/Stack/blob/master/CONTRIBUTING.md#a-typical-contributor-workflow)_
- [ ] 1. The issue provides a reproduction available on [GitHub](https://github.com/dotansimha/graphql-code-generator-issue-sandbox-template), [Stackblitz](https://stackblitz.com/github/dotansimha/graphql-code-generator-issue-sandbox-template) or [CodeSandbox](https://codesandbox.io/s/github/dotansimha/graphql-code-generator-issue-sandbox-template)
> Make sure to fork this template and run `yarn generate` in the terminal.
>
> Please make sure the Codegen and plugins version under `package.json` matches yours.
- [ ] 2. A failing test has been provided
- [ ] 3. A local solution has been provided
- [ ] 4. A pull request is pending review
---
**Describe the bug**
Types are not configured correctly for Typescript 4.7 and Node16+ module resolution usage.
[This comment](https://github.com/microsoft/TypeScript/issues/49160#issuecomment-1137482639 points at why errors would be occuring despite there being a "types" field and the `*.d.ts` files are present in the packages.
```
src/executors/gql.ts(6,25): error TS7016: Could not find a declaration file for module '@graphql-codegen/core'. '/home/chris/projects/_/node_modules/@graphql-codegen/core/index.mjs' implicitly has an 'any' type.
Try `npm i --save-dev @types/graphql-codegen__core` if it exists or add a new declaration (.d.ts) file containing `declare module '@graphql-codegen/core';`
src/executors/gql.ts(7,23): error TS7016: Could not find a declaration file for module '@graphql-codegen/add'. '/home/chris/projects/_/node_modules/@graphql-codegen/add/index.mjs' implicitly has an 'any' type.
Try `npm i --save-dev @types/graphql-codegen__add` if it exists or add a new declaration (.d.ts) file containing `declare module '@graphql-codegen/add';`
src/executors/gql.ts(8,35): error TS7016: Could not find a declaration file for module '@graphql-codegen/typescript'. '/home/chris/projects/_/node_modules/@graphql-codegen/typescript/index.mjs' implicitly has an 'any' type.
Try `npm i --save-dev @types/graphql-codegen__typescript` if it exists or add a new declaration (.d.ts) file containing `declare module '@graphql-codegen/typescript';`
src/executors/gql.ts(9,44): error TS7016: Could not find a declaration file for module '@graphql-codegen/typescript-resolvers'. '/home/chris/projects/_/node_modules/@graphql-codegen/typescript-resolvers/index.mjs' implicitly has an 'any' type.
Try `npm i --save-dev @types/graphql-codegen__typescript-resolvers` if it exists or add a new declaration (.d.ts) file containing `declare module '@graphql-codegen/typescript-resolvers';`
src/executors/gql.ts(10,45): error TS7016: Could not find a declaration file for module '@graphql-codegen/typescript-operations'. '/home/chris/projects/_/node_modules/@graphql-codegen/typescript-operations/index.mjs' implicitly has an 'any' type.
Try `npm i --save-dev @types/graphql-codegen__typescript-operations` if it exists or add a new declaration (.d.ts) file containing `declare module '@graphql-codegen/typescript-operations';`
```
**To Reproduce**
Attempt to programatically use any codegen package from a "type: module" package with the following tsconfig. Build with tsc.
```
{
"compilerOptions": {
"target": "ES2021",
"lib": ["ES2021"],
"skipLibCheck": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "node16",
"moduleResolution": "node16",
"allowJs": true,
"resolveJsonModule": true,
"isolatedModules": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
}
}
```
**Expected behavior**
Compiles successfully.
**Environment:**
- OS: Ubuntu
- `@graphql-codegen/...`: `@graphql-codegen/typescript-operations` for example but any will break
- NodeJS: 16.15
**Additional context**
https://github.com/microsoft/TypeScript/issues/49160#issuecomment-1137482639
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.