graphql-codegen will not start the local development server if placed inside ...

David Tu
2023-03-09T19:14:33Z

graphql-codegen will not start the local development server if placed inside the "src" directory

<!--
Please note that your issue will be fixed much faster if you spend about
half an hour preparing it, including the exact reproduction steps and a demo.

If you're in a hurry or don't feel confident, it's fine to report bugs with
less details, but this makes it less likely they'll get fixed soon.

In either case, please use this template and fill in as many fields below as you can.

Note that we don't provide help for webpack questions after ejecting.
You can find webpack docs at https://webpack.js.org/.
-->

### 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:

```bash
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:

```bash
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?

<!--
Your module tree might be corrupted, and that might be causing the issues.
Let's try to recover it. First, delete these files and folders in your project:

* node_modules
* package-lock.json
* yarn.lock

Then you need to decide which package manager you prefer to use.
We support both npm (https://npmjs.com) and yarn (https://yarnpkg.com/).
However, **they can't be used together in one project** so you need to pick one.

If you decided to use npm, run this in your project directory:

npm install -g npm@latest
npm install

This should fix your project.

If you decided to use yarn, update it first (https://yarnpkg.com/en/docs/install).
Then run in your project directory:

yarn

This should fix your project.

Importantly, **if you decided to use yarn, you should never run `npm install` in the project**.
For example, yarn users should run `yarn add <library>` instead of `npm install <library>`.
Otherwise your project will break again.

Have you done all these steps and still see the issue?
Please paste the output of `npm --version` and/or `yarn --version` to confirm.
-->

I am using yarn -- I have tried deleting `node_modules`, `yarn.lock`, etc. Nothing worked.
**yarn version: 1.22.19**

### Environment

<!--
To help identify if a problem is specific to a platform, browser, or module version, information about your environment is required.
This enables the maintainers quickly reproduce the issue and give feedback.

Run the following command in your React app's folder in terminal.
Note: The result is copied to your clipboard directly.

`npx create-react-app --info`

Paste the output of the command in the section below.
-->

```bash
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

<!--
How would you describe your issue to someone who doesn’t know you or your project?
Try to write a sequence of steps that anybody can repeat to see the issue.
-->

(Write your steps here:)

1. If you have graphql and graphql-codegen set up, create a few queries and run codegen. Have it output into the `src` directory.
2. Run the local server
3. Observe it might freeze.
4. generate the queries outside of the `src` directory
5. run the local development server.
6. import it. It will complain that I can't import from outside the `src` directory.

### Expected behavior

<!--
How did you expect the tool to behave?
It’s fine if you’re not sure your understanding is correct.
Just write down what you thought would happen.
-->

The expected behavior is to have the local development server start normally despite having a large file generated in `src`

### Actual behavior

<!--
Did something go wrong?
Is something broken, or not behaving as you expected?
Please attach screenshots if possible! They are extremely helpful for diagnosing issues.
-->

Local development server hangs indefinitely.