dotansimha / graphql-yoga

🧘 Rewrite of a fully-featured GraphQL Server with focus on easy setup, performance & great developer experience. The core of Yoga implements WHATWG Fetch API and can run/deploy on any JS environment.
https://the-guild.dev/graphql/yoga-server
MIT License
8.13k stars 561 forks source link

Critical dependency warning in Next 13 (Turborepo) #3049

Open elirandpg opened 9 months ago

elirandpg commented 9 months ago

Describe the bug

Hey guys,

First, I apologize for not setting up a codesandbox for this, the setup alone would take hours in my current config. So I'm really wondering if you guys might have a quick win here?

I'm getting this in my terminal on every access to the Yoga server -

 ⚠ ../../node_modules/.pnpm/@whatwg-node+fetch@0.9.13/node_modules/@whatwg-node/fetch/dist/node-ponyfill.js
Critical dependency: the request of a dependency is an expression

Import trace for requested module:
../../node_modules/.pnpm/@whatwg-node+fetch@0.9.13/node_modules/@whatwg-node/fetch/dist/node-ponyfill.js
../../node_modules/.pnpm/graphql-yoga@4.0.5_graphql@16.8.1/node_modules/graphql-yoga/esm/server.js
../../node_modules/.pnpm/graphql-yoga@4.0.5_graphql@16.8.1/node_modules/graphql-yoga/esm/index.js
./app/api/graphql/route.ts

Contents of route.ts:

import { createSchema, createYoga } from 'graphql-yoga';

import { dealerResolvers } from './resolvers/dealers';
import sharedSchema from './schema.graphql';

const schema = createSchema({
    typeDefs: [sharedSchema],
    resolvers: [dealerResolvers],
});

const { handleRequest } = createYoga({
    graphqlEndpoint: '/api/graphql',
    fetchAPI: { Request, Response },
    schema,
});

export { handleRequest as GET, handleRequest as POST };

I'm using Node v20.2 and the latest Next and Turborepo builds, and as you probably noticed the App router. Everything works as expected, but this warning is spamming my logs. It goes without saying that before Yoga my terminal was free of warnings. Wdyt?

Thanks!

Your Example Website or App

https://codesandbox.io/

Steps to Reproduce the Bug or Issue

My setup is in turborepo with a bunch of interconnected packages and applications. I'm not sure it can be replicated in a stable manner without our external services.

Expected behavior

The terminal shouldn't have dependency warnings.

Screenshots or Videos

No response

Platform

Additional context

No response

Luferov commented 9 months ago

To reproduce

git clone https://github.com/Luferov/soulmagic pnpm i pnpm run dev

SoraKumo001 commented 9 months ago

This avoids the warning.

/**
 * @type { import("next").NextConfig}
 */
const config = {
  experimental: {
    serverComponentsExternalPackages: ["@whatwg-node"],
  },
};
module.exports = config;
elirandpg commented 9 months ago

This avoids the warning.

/**
 * @type { import("next").NextConfig}
 */
const config = {
  experimental: {
    serverComponentsExternalPackages: ["@whatwg-node"],
  },
};
module.exports = config;

Thank you, but unfortunately for me the warning persists. :(

ardatan commented 9 months ago

We'll take a look but this is just a warning, and it shouldn't have any effect on runtime.

elirandpg commented 9 months ago

You're right, everything does work as it should, like I said. I will just have to filter it out of our logs specifically since it is very frequent. Thanks again!

Luferov commented 9 months ago

First of all, when I open /api/graphql this error still exist.

image

Second of all, all GraphQL queries doesn't work. 🥲

image
ardatan commented 9 months ago

First of all, when I open /api/graphql this error still exist.

This looks like a different error. Please create a different issue with a reproduction.