apollographql / apollo-tooling

✏️ Apollo CLI for client tooling (Mostly replaced by Rover)
https://apollographql.com
MIT License
3.04k stars 468 forks source link

how to use apollo.config.js with Vite React app #2688

Open PuffCab opened 1 year ago

PuffCab commented 1 year ago

I am trying to use Apollo extension in a React application created with Vite.

I create apollo.config.js at the root folder, following the intructions, like this : module.exports = { client: { service: { name: "my-graphql-app", url: "http://localhost:4000/graphql", }, }, };

But i get the error "'module' is not defined." , since it is not an E6 Module. Therefore Apollo extension cannot find the file, getting this error from the extension :
Service stats could not be loaded. This may be because you're missing an apollo.config.js file or it is misconfigured.

How could I convert it to an E6 Module, or how should i create the config file to be able to use it in a React App using Vite?

If I use CreateReactApp to create the React app, then there is no issue.

idonov commented 9 months ago

Just had the same issue with Vite. Simple fix, just rename it to apollo.config.cjs so Vite will treat it as CommonJS