question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

New version of webpack creating GraphQL schema conflicts on NestJS app when optimization is true

See original GitHub issue

Current Behavior

Migrating @nrwl/node from version "14.7.5" to "14.7.10" or "14.7.11" creates a name collision when building a @nestjs/graphql app in production mode ("optimization": true).

Expected Behavior

Updating @nrwl/node from version "14.7.5" to version "14.7.11" should still build the NestJS app as previously.

Steps to Reproduce

Minimal example repo: nx-webpack-bug

Install all dependencies and run yarn nx serve backend --prod.

It will fail with a message: Error: Schema must contain uniquely named types but contains multiple types named "l".

Change the version of @nrwl/node to "14.7.5", then change the build executor of the apps/backend/project.json file from @nrwl/webpack:webpack to @nrwl/node:webpack. Running yarn nx serve backend --prod will succeed.

When optimization is true, some GraphQL names end up having the same name, and so the process fails. This was most likely introduced with the latest changes of moving the webpack plugin.

I have gotten far in creating a minimally reproducible example, so I feel close to the issue. If I get some minimal direction I would love to dig deeper and provide a PR to solve it. ❤️

Failure Logs

=> yarn nx serve backend --prod


yarn run v1.22.19
$ /Users/my-user/Code/example/debug/node_modules/.bin/nx serve backend --prod

> nx run backend:serve:production

chunk (runtime: main) main.js (main) 5.01 KiB [entry] [rendered]
webpack compiled successfully (eead8f67e9d7eaa9)
Debugger listening on ws://localhost:9229/e5718c63-071a-4300-ab4f-279625903eda
Debugger listening on ws://localhost:9229/e5718c63-071a-4300-ab4f-279625903eda
For help, see: https://nodejs.org/en/docs/inspector
[Nest] 50987  - 23/09/2022, 16:29:37     LOG [NestFactory] Starting Nest application...
[Nest] 50987  - 23/09/2022, 16:29:37     LOG [InstanceLoader] n dependencies initialized +18ms
[Nest] 50987  - 23/09/2022, 16:29:37     LOG [InstanceLoader] i dependencies initialized +0ms
[Nest] 50987  - 23/09/2022, 16:29:37     LOG [InstanceLoader] GraphQLSchemaBuilderModule dependencies initialized +1ms
[Nest] 50987  - 23/09/2022, 16:29:37     LOG [InstanceLoader] GraphQLModule dependencies initialized +0ms

/Users/my-user/Code/example/debug/node_modules/graphql/type/schema.js:219
        throw new Error(
              ^
Error: Schema must contain uniquely named types but contains multiple types named "l".
    at new GraphQLSchema (/Users/my-user/Code/example/debug/node_modules/graphql/type/schema.js:219:15)
    at GraphQLSchemaFactory.create (/Users/my-user/Code/example/debug/node_modules/@nestjs/graphql/dist/schema-builder/graphql-schema.factory.js:40:24)
    at GraphQLSchemaBuilder.generateSchema (/Users/my-user/Code/example/debug/node_modules/@nestjs/graphql/dist/graphql-schema.builder.js:35:52)
    at GraphQLSchemaBuilder.build (/Users/my-user/Code/example/debug/node_modules/@nestjs/graphql/dist/graphql-schema.builder.js:22:31)
    at GraphQLFactory.mergeWithSchema (/Users/my-user/Code/example/debug/node_modules/@nestjs/graphql/dist/graphql.factory.js:29:69)
    at ApolloDriver.start (/Users/my-user/Code/example/debug/node_modules/@nestjs/apollo/dist/drivers/apollo.driver.js:19:51)
    at GraphQLModule.onModuleInit (/Users/my-user/Code/example/debug/node_modules/@nestjs/graphql/dist/graphql.module.js:105:36)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at callModuleInitHook (/Users/my-user/Code/example/debug/node_modules/@nestjs/core/hooks/on-module-init.hook.js:51:9)
    at NestApplication.callInitHook (/Users/my-user/Code/example/debug/node_modules/@nestjs/core/nest-application-context.js:178:13)

Environment

MacOS Monterey v12.3.1 (Apple M1 Max)

node v16.16.0
yarn v1.22.19

"nx": "14.7.11"
"@nrwl/node": "14.7.11"
"@nrwl/nest": "14.7.11"
"@nestjs/apollo": "^10.1.0"
"@nestjs/graphql": "^10.1.2"
// See package.json for other dependencies
=> yarn nx report

yarn run v1.22.19
$ /Users/my-user/Code/example/debug/node_modules/.bin/nx report

 >  NX   Report complete - copy this into the issue template

   Node : 16.16.0
   OS   : darwin arm64
   yarn : 1.22.19
   
   nx : 14.7.11
   @nrwl/angular : Not Found
   @nrwl/cypress : Not Found
   @nrwl/detox : Not Found
   @nrwl/devkit : 14.7.11
   @nrwl/eslint-plugin-nx : 14.7.11
   @nrwl/expo : Not Found
   @nrwl/express : Not Found
   @nrwl/jest : 14.7.11
   @nrwl/js : 14.7.11
   @nrwl/linter : 14.7.11
   @nrwl/nest : 14.7.11
   @nrwl/next : Not Found
   @nrwl/node : 14.7.11
   @nrwl/nx-cloud : 14.6.2
   @nrwl/nx-plugin : Not Found
   @nrwl/react : Not Found
   @nrwl/react-native : Not Found
   @nrwl/schematics : Not Found
   @nrwl/storybook : Not Found
   @nrwl/web : Not Found
   @nrwl/workspace : 14.7.11
   typescript : 4.8.3
   ---------------------------------------
   Local workspace plugins:
   ---------------------------------------
   Community plugins:

✨  Done in 0.42s.

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:8
  • Comments:16

github_iconTop GitHub Comments

4reactions
scomanscommented, Oct 4, 2022

As a workaround you can use a custom webpack config for your nest projects and disable minimize:

module.exports = (config, context) => {
  config.optimization = { minimize: false };
  return config;
};
3reactions
SmoshySmoshcommented, Oct 28, 2022

changing “optimization” to false work for me

Same for me, but it’s not a long term solution as it does not minify the production release.

Read more comments on GitHub >

github_iconTop Results From Across the Web

NestJS Graphql webpack production build Error - Stack Overflow
This is especially a problem for NestJS GraphQL schema if you are using ... optimization: { minimize: true, minimizer: [ new TerserPlugin({ ...
Read more >
How to build an Apollo GraphQL server with TypeScript and ...
This post is part 1 of the Apollo GrpahQL: How-to series: Part 1: How to build an Apollo GraphQL server with TypeScript and...
Read more >
Building GraphQL APIs with TypeGraphQL and TypeORM
TypeGraphQL is a framework for building GraphQL APIs with Node.js and TypeScript. The main purpose of this tool is to let us define...
Read more >
Schema Directives – GraphQL Tools
Using and implementing custom directives to transform schema types, fields, and arguments.
Read more >
Building Type Safe Backend Apps with Typegoose and ...
With this setup, we got four files per model: model, resolver, service, and GraphQL schema file. That's too many things to keep in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found