graphql-codegen will not start the local development server if placed inside the "src" directory
Describe the bug
I am in the process of setting up [graphql-codegen](https://github.com/dotansimha/graphql-code-generator)
and I've come to a realization that when trying to generate my types, queries, and mutations in my src
directory, when I start my local development server (react-scripts start
), I get this output from my console:
Starting the development server...
However, this hangs for a long time. I'm not even sure if it will compile or do anything. As of writing, I've let it sit for more than 10 minutes with no movement. There are no errors. The code generated is about 8000 lines long, so I'm wondering if it could be that.
I've tried deleting that and moving my code outside of the src
directory and I was actually able to start my server in a few seconds. I thought this would help, but when I try to import something outside of the src
directory, I am met with this error:
Module not found: Error: You attempted to import ../../../generated/graphql which falls outside of the project src/ directory. Relative imports outside of src/ are not supported.
You can either move it inside src/, or add a symlink to it from project's node_modules/.
To the last point of using symlink, I tried going about this route, but I would need to set up babel since the generated code uses things like import
and export
, and I feel like that's overkill, though it seems like the only realistic option for now.
Did you try recovering your dependencies?
I am using yarn -- I have tried deleting node_modules
, yarn.lock
, etc. Nothing worked.
yarn version: 1.22.19
Environment
npx create-react-app --info
Need to install the following packages:
create-react-app
Ok to proceed? (y) y
npm WARN deprecated tar@2.2.2: This version of tar is no longer supported, and will not receive security updates. Please upgrade asap.
Environment Info:
current version of create-react-app: 5.0.1
running from /Users/david/.npm/_npx/c67e74de0542c87c/node_modules/create-react-app
System:
OS: macOS 13.2
CPU: (10) arm64 Apple M1 Pro
Binaries:
Node: 16.15.1 - /usr/local/bin/node
Yarn: 1.22.19 - /usr/local/bin/yarn
npm: 8.11.0 - /usr/local/bin/npm
Browsers:
Chrome: 110.0.5481.177
Edge: Not Found
Firefox: 107.0.1
Safari: 16.3
npmPackages:
react: ^18.1.0 => 18.2.0
react-dom: ^18.1.0 => 18.2.0
react-scripts: 5.0.1 => 5.0.1
npmGlobalPackages:
create-react-app: Not Found
Steps to reproduce
(Write your steps here:)
- If you have graphql and graphql-codegen set up, create a few queries and run codegen. Have it output into the
src
directory. - Run the local server
- Observe it might freeze.
- generate the queries outside of the
src
directory - run the local development server.
- import it. It will complain that I can't import from outside the
src
directory.
Expected behavior
The expected behavior is to have the local development server start normally despite having a large file generated in src
Actual behavior
Local development server hangs indefinitely.