[ ] Regression
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
When I update NestJS to the newest version, the @nestjs/graphql can't find some modules during build.

The project should build.
Nest version: 8.0.0
For Tooling issues:
- Node version: v14.17.0
- Platform: Linux and Windows
The missing modules are ts-morph and @apollo/gateway. That was in the screenshot. I'm adding this comment to make it searchable.
I worked around this by adding the modules as dependencies in my project. I'd prefer not to have these "sub-dependencies" referenced in package.json.
That's actually something that we've been struggling with for a while already.
Both packages (ts-morph and @apollo/gateway) are _optional_. For example, if you're building a code-first GraphQL application (not federated), neither library is technically required. A different example would be if you had a code-first GQL Federated API, in this case, you need the @apollo/gateway library, but you'd never really interact with the ts-morph.
In the past, both libraries were included (auto-installed) by default as they were specified as "optionalDependencies". Now, they are registered as optional "peerDependencies" so their behavior will differ depending on what NPM version (NPM v7 automatically installs peer deps) you use/tsconfig settings you have. We made that change (moved these packages to the peerDependencies section) because ts-morph is quite a heavy package (since it's a compiler wrapper), not needed for all code first GraphQL apps.
Solutions:
a) manually install both deps (npm i ts-morph @apollo/gateway)
b) OR disable lib types checking in your tsconfig.json file (compilerOptions.skipLibCheck set to true) - this is the default value for new Nest projects as well
For those (like me) getting errors like
UnhandledPromiseRejectionWarning: Error: You must `await server.start()` before calling `server.apply Middleware()`
when using "apollo-server-express": "^3.0.0", there's already a fix https://github.com/nestjs/graphql/pull/1627 on the way 馃檶
Thank you. I was able to get things working by setting compilerOptions.skipLibCheck to true (not false, I believe that was a typo).
My tsconfig.json was created under Nest 7.x and didn't have skipLibCheck set so that was why I was seeing the error.
@DaniSchenk https://github.com/nestjs/nest/issues/7543#issuecomment-878811893
My solution is neither a) nor b), I prefer to c) explicitly declare the few missing types over skipping library type checks alltogether, on the other hand I did not run in any import issues with ts-morph so far.
// src/graphql-gateway-type-shim.d.ts
declare module '@apollo/gateway' {
export interface GatewayConfig { }
export interface ServiceEndpointDefinition { }
}
declare module '@apollo/gateway/dist/datasources/types' {
export interface GraphQLDataSource { }
}
Most helpful comment
That's actually something that we've been struggling with for a while already.
Both packages (
ts-morphand@apollo/gateway) are _optional_. For example, if you're building a code-first GraphQL application (not federated), neither library is technically required. A different example would be if you had a code-first GQL Federated API, in this case, you need the@apollo/gatewaylibrary, but you'd never really interact with thets-morph.In the past, both libraries were included (auto-installed) by default as they were specified as "optionalDependencies". Now, they are registered as optional "peerDependencies" so their behavior will differ depending on what NPM version (NPM v7 automatically installs peer deps) you use/tsconfig settings you have. We made that change (moved these packages to the
peerDependenciessection) becausets-morphis quite a heavy package (since it's a compiler wrapper), not needed for all code first GraphQL apps.Solutions:
a) manually install both deps (
npm i ts-morph @apollo/gateway)b) OR disable lib types checking in your
tsconfig.jsonfile (compilerOptions.skipLibCheckset totrue) - this is the default value for new Nest projects as well