Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript Error after update to apollo-server-express 2.11.0 #3858

Closed
andreastoermer opened this issue Mar 4, 2020 · 19 comments
Closed

Typescript Error after update to apollo-server-express 2.11.0 #3858

andreastoermer opened this issue Mar 4, 2020 · 19 comments
Labels
🧬 typings Relates to TypeScript changes or improvements.

Comments

@andreastoermer
Copy link

I update apollo-server-express package from 2.10.1 to 2.11.0 and during the build process of the application I get the following Typescript error message:

node_modules/@apollo/gateway/node_modules/apollo-cache-control/dist/index.d.ts:24:9 - error TS2717: Subsequent property declarations must have the same type.  Property 'cacheControl' must be of type '{ setCacheHint: (hint: CacheHint) => void; cacheHint: CacheHint; }', but here has type '{ setCacheHint: (hint: CacheHint) => void; cacheHint: CacheHint; }'.
 24         cacheControl: {
            ~~~~~~~~~~~~
   node_modules/apollo-cache-control/dist/index.d.ts:24:9
     24         cacheControl: {
                ~~~~~~~~~~~~
     'cacheControl' was also declared here.

When I return back to version 2.10.1, everything is ok.

@bke-daniel
Copy link

Same over here. Deleting node_modules and package-lock.json and reinstalling didn't work.
Everything is on latest available Version.

@chrislambe
Copy link

chrislambe commented Mar 6, 2020

Edit: resolved by upgrading apollo-server-plugin-response-cache to 0.4.0.

I'm seeing this issue even with apollo-server-express on version 2.10.1.

$ `yarn bin`/tsc
node_modules/apollo-server-core/node_modules/apollo-cache-control/dist/index.d.ts:24:9 - error TS2717: Subsequent property declarations must have the same type.  Property 'cacheControl' must be of type '{ setCacheHint: (hint: CacheHint) => void; cacheHint: CacheHint; }', but here has type '{ setCacheHint: (hint: CacheHint) => void; cacheHint: CacheHint; }'.

24         cacheControl: {
           ~~~~~~~~~~~~

  node_modules/apollo-cache-control/dist/index.d.ts:24:9
    24         cacheControl: {
               ~~~~~~~~~~~~
    'cacheControl' was also declared here.


Found 1 error.

$ yarn list --pattern apollo-server-express
yarn list v1.22.0
└─ [email protected]
✨  Done in 0.88s.

@abernix
Copy link
Member

abernix commented Mar 19, 2020

@andreastoermer Could you try and confirm whether the suggestion by @chrislambe resolves it for you and close this if so? Thanks!

@abernix abernix added the 🧬 typings Relates to TypeScript changes or improvements. label Mar 19, 2020
@thenameisangel
Copy link

@andreastoermer @bke-daniel Did you guys end up resolving this issue? I'm experiencing similar issues on version 2.12.0.

@abernix
Copy link
Member

abernix commented May 5, 2020

@thenameisangel What is the output you receive when you run npm ls apollo-cache-control?

@andreastoermer
Copy link
Author

I can only fix the current problem, when I set SkipLibCheck to true in tsconfig. But that's only my workarround (and not a good one). When I set it to false, I get the error again (with 2.12.0)

@bke-daniel
Copy link

Adding apollo-cache-control manually to package.json with version 0.10.0 fixes the issue.

@thenameisangel
Copy link

@abernix I ran npm ls apollo-cache-control and noticed that that apollo-cache-control version in the apollo-server-core subdirectory was 0.9.1 while the other apollo-cache-control packages were 0.10.1. I did a global uninstall of apollo-server-core and re-installed the package, and it resolved the issue. However, this failed once I push my changes upstream, as the CI/CD pipeline that runs on my upstream branch simply runs a npm install and doesn't install each package individually.

I tried @bke-daniel's suggestion of manually adding apollo-cache-control version 0.10.0 in the package.json, cleared the node modules, and ran npm install again, and this resolved the issue. Thank you guys for the help!

@marcoreni
Copy link

FYI I had the same issue updating from [email protected] to [email protected].

Fixed by installing apollo-cache-control@^0.10.1-alpha.0.

@abernix Is it correct that apollo-server-core 2.13.1 references a lot of alpha dependencies?

apollo-server-core@^2.13.1:
  version "2.13.1"
  resolved "https://registry.yarnpkg.com/apollo-server-core/-/apollo-server-core-2.13.1.tgz#eac223696ae9da5f4990273ea89c74b77af0e156"
  integrity sha512-4jKF0VbpoxprhcruaGoHG5ScrquSSkQ/LVFrOLp/ukUFuooLEMb1O18tAQdgVahkNgLkRKdNJYLLyoQoj+i3dA==
  dependencies:
    "@apollographql/apollo-tools" "^0.4.3"
    "@apollographql/graphql-playground-html" "1.6.24"
    "@types/graphql-upload" "^8.0.0"
    "@types/ws" "^7.0.0"
    apollo-cache-control "^0.10.1-alpha.0"
    apollo-datasource "^0.7.1-alpha.0"
    apollo-engine-reporting "^1.8.1-alpha.0"
    apollo-server-caching "^0.5.1"
    apollo-server-env "^2.4.4-alpha.0"
    apollo-server-errors "^2.4.1"
    apollo-server-plugin-base "^0.8.1-alpha.0"
    apollo-server-types "^0.4.1-alpha.0"
    apollo-tracing "^0.10.1-alpha.0"
    fast-json-stable-stringify "^2.0.0"
    graphql-extensions "^0.12.1-alpha.0"
    graphql-tag "^2.9.2"
    graphql-tools "^4.0.0"
    graphql-upload "^8.0.2"
    loglevel "^1.6.7"
    sha.js "^2.4.11"
    subscriptions-transport-ws "^0.9.11"
    ws "^6.0.0"

@bke-daniel
Copy link

@marcoreni Correct, due to the version bumps it needs to be [email protected] by now.

@ckaminski
Copy link

Still an issue with 0.11.1?

Using NestJS:
"dependencies": {
"@nestjs/common": "^7.4.2",
"@nestjs/core": "^7.4.2",
"@nestjs/graphql": "^7.6.0",
"@nestjs/passport": "^7.1.0",
"@nestjs/platform-express": "^7.4.2",
"@nestjs/typeorm": "^7.1.0",
"apollo-cache-control": ""
"apollo-server-express": "^2.16.1",
"class-transformer": "^0.2.3",
"class-validator": "^0pg.12.2",
"graphql": "^15.3.0",
"graphql-tools": "^6.0.15",
"passport": "^0.4.1",
"passport-local": "^1.0.0",
"pg": "^8.3.0",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"rxjs": "^6.6.2",
"typeorm": "^0.2.25"
},

@Huljo
Copy link

Huljo commented Aug 6, 2020

Having the issue with 0.11.1.
Adding [email protected] is not fixing the problem in my case.
@marcoreni did you just changed "apollo-cache-control": "0.10.1-alpha.0" to your apollo-server-core package.json ?
Our CI is still failing due to this issue.
yarn list apollo-cache-control
└─ [email protected]
└─ [email protected]

@munjalpatel
Copy link

Also having the same issue:

image

npm ls apollo-cache-control

[email protected] /Users/.../backend
├─┬ @nestjs/[email protected]
│ └─┬ [email protected]
│   └── [email protected]
└─┬ [email protected]
  └─┬ [email protected]
    └── [email protected]

@glasser
Copy link
Member

glasser commented Sep 21, 2020

So TypeScript supports module augmentation and interface merging. It claims that:

Non-function members of the interfaces should be unique. If they are not unique, they must be of the same type. The compiler will issue an error if the interfaces both declare a non-function member of the same name, but of different types.

But for some reason it thinks the additions to GraphQLResolveInfo in apollo-cache-control are not "the same type". I'm not sure if this is a TS bug or there's some good reason for this.

When using prereleases of npm modules, it's a lot easier to end up with two versions of a module in your node_modules tree, where your explicit use of the prerelease pulls in a whole subtree of prerelease Apollo Server modules but some other module pulls in a subtree of non-prerelease Apollo Server modules, and then you have two copies of apollo-cache-control and TypeScript gets sad.

I don't feel great about this suggestion, but one thing that does work (if you're pretty sure that the prerelease of apollo-cache-control doesn't actually differ from the released version in an important way — eg if we've only changed comments or README or something else not relevant to your lifestyle) is to add

    "baseUrl": ".",
    "paths": {
      "apollo-cache-control": ["node_modules/apollo-cache-control"]
    }

to your app's tsconfig.json. ie, to tell it only to read the top-level ACC module no matter what.

Not a compelling answer but it is working for my own app testing!

@jobsofferings
Copy link

@andreastoermer

I did the same thing as you

I did the same thing as you, but this is just a temporary solution.

I tried to install an apollo-cache-control and added a package.json configuration

  "paths": {
    "apollo-cache-control": [
      "node_modules/apollo-cache-control"
    ]
  }

When i run: npm ls apollo-cache-control

├─┬ @nestjs/[email protected]
│ └─┬ [email protected]
│   └─┬ [email protected]
│     └── [email protected]  deduped
├── [email protected] 
└─┬ [email protected]
  └─┬ [email protected]
    └── [email protected]  deduped

But it is always ineffective. Do you have a good solution now?

@glasser
Copy link
Member

glasser commented Jul 20, 2021

For what it's worth, the location of this declare module moved from apollo-cache-control to apollo-server-core in Apollo Server 3, and we're moving it to apollo-server-types now (#5512). This might help a bit.

Otherwise, I think this issue mostly just happens when there are alphas out, and using the tsconfig.json / paths trick does work, so I'm going to close this for now.

@glasser glasser closed this as completed Jul 20, 2021
@jbrainz
Copy link

jbrainz commented Jul 22, 2021

i'm still having these issue even after trying to tweak the tsconfig.json file
Screenshot from 2021-07-22 08-49-01
Screenshot from 2021-07-22 08-50-22

@glasser
Copy link
Member

glasser commented Jul 22, 2021

npm dedup may help here. It looks like you may be mixing Apollo Server 2 with 3 (apollo-cache-control is only in AS2 and the referenced apollo-server-types line was added in AS 3.0.2).

@jbrainz
Copy link

jbrainz commented Jul 22, 2021

Thanks, i was able to fix this from #3339 (comment)

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🧬 typings Relates to TypeScript changes or improvements.
Projects
None yet
Development

No branches or pull requests