After updating to NextJS 13.5 I started seeing these errors when deployed on Vercel (but works fine locally):
Error: Schema must contain uniquely named types but contains multiple
types named "h".
at new GraphQLSchema (/var/task/node_modules/.pnpm/[email protected]/node_modules/graphql/type/schema.js:219:15)
My init code is pretty straightforward in the serverless function:
const schema = buildSchemaSync({
authChecker: UserAuthority,
resolvers: [...]
});
const plugins = [
// Install a landing page plugin based on NODE_ENV
process.env.NODE_ENV === 'production'
? ApolloServerPluginLandingPageProductionDefault({
graphRef: 'my-graph-id@my-graph-variant',
footer: false,
})
: ApolloServerPluginLandingPageLocalDefault({ footer: false }),
];
const server = new ApolloServer({
schema,
introspection: true,
csrfPrevention: true,
plugins,
cache: 'bounded'
// enable GraphQL Playground
});
const handler = startServerAndCreateNextHandler(server, {
context
})
await handler(req, res);
This seems to be related to Next optimisations given there are no types named ‘h’. Is there a way to ensure every unique name generated as part of optimization’s is unique?
1 Answer
This may be a little drastic, but you could try disabling minimisation in the Webpack config for Next.js.
next.config.js
:
config.optimization.minimize = false;
As per https://webpack.js.org/configuration/optimization/#optimizationminimize.
If nothing else, it may help narrow down the cause of the error you are now receiving.