graphile / crystal

🔮 Graphile's Crystal Monorepo; home to Grafast, PostGraphile, pg-introspection, pg-sql2 and much more!
https://graphile.org/
Other
12.61k stars 571 forks source link

`Cannot find module 'ruru/server' or its corresponding type declarations.` #2237

Closed kasir-barati closed 6 hours ago

kasir-barati commented 7 hours ago

Summary

I use pnpm everywhere and when I install ruru like this pnpm add ruru and try to import it I get this error message in my terminal when it tries to build it and in my IDE as well. It looks to me there are some issues with types exported from ruru.

Steps to reproduce

Clone this repo and remove // @ts-ignore here: https://github.com/kasir-barati/graphql/blob/0a1b9b7f822798f9a8d8449c73bd6e5fc5d932ae/apps/expressjs-hello-world/src/main.ts#L4

Expected results

Just work like you should

Actual results

** NX   Running target serve for project expressjs-hello-world and 1 task it depends on:

—————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————

> nx run expressjs-hello-world:build:production

apps/expressjs-hello-world/src/main.ts:5:26 - error TS2307: Cannot find module 'ruru/server' or its corresponding type declarations.
  There are types at '/home/kasir/projects/graphql/node_modules/ruru/dist/server.d.ts', but this result could not be resolved under your current 'moduleResolution' setting. Consider updating to 'node16', 'nodenext', or 'bundler'.

  3 | import { createHandler } from 'graphql-http/lib/use/express';
  4 | 
> 5 | import { ruruHTML } from 'ruru/server';
    |                          ^
  6 | 
  7 | const schema = buildSchema(`
  8 |   type Query {

Found 1 error.

—————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————

 NX   Running target serve for project expressjs-hello-world and 1 task it depends on failed

Failed tasks:

- expressjs-hello-world:build:production

Hint: run the command with --verbose for more details.**

Additional context

I am using Nx and it is a monorepo. I am building it with esbuild.

Possible Solution

Maybe add some types over there.

kasir-barati commented 7 hours ago

Please note that it works. My problem with it is that I had to use // @ts-ignore and I wanna avoid using it AMAP.

benjie commented 7 hours ago

Your TypeScript is configured as if you're still back in Node14 (or before) land. Please consider extending from a modern TypeScript configuration, e.g.:

{
  "extends": "@tsconfig/node20/tsconfig.json"
}

The actual setting that is incorrect is the moduleResolution setting, which needs to be updated to node16 or nodenext; we don't have docs for that in Ruru yet but it's equivalent to these PostGraphile docs:

https://postgraphile.org/postgraphile/next/requirements#typescript-v500-optional

kasir-barati commented 6 hours ago

Thanks for linking the official doc so that I can learn more about this. I guess then this was an oversight on my end. I am gonna close this since I thought it is something related to pnpm/nx.