wincent / masochist

⛓ Website infrastructure for over-engineers
MIT License
78 stars 26 forks source link

Solve `TS2307: Cannot find module` #210

Closed wincent closed 1 year ago

wincent commented 1 year ago

Since adding a new package or two, I've been seeing this on first yarn build (after a git clean -fdx packages, or in CI).

packages/benchmark/src/benchmark-static-lexer.ts:1:19 - error TS2307: Cannot find module '@masochist/graphql' or its corresponding type declarations.

1 import {lex} from '@masochist/graphql';
                    ~~~~~~~~~~~~~~~~~~~~

packages/benchmark/src/benchmark-static-parser.ts:1:29 - error TS2307: Cannot find module '@masochist/graphql' or its corresponding type declarations.

1 import {parseDocument} from '@masochist/graphql';
                              ~~~~~~~~~~~~~~~~~~~~

packages/benchmark/src/benchmark-table-parser.ts:1:35 - error TS2307: Cannot find module '@masochist/graphql' or its corresponding type declarations.

1 import {grammar, lex, table} from '@masochist/graphql';
                                    ~~~~~~~~~~~~~~~~~~~~

Found 3 errors.

Second yarn build invocation works.

No circular dependencies, as far as I am aware. node_modules looks fine with proper symlinks (and issue repros anyway after a rm -r node_modules):

lrwxr-xr-x    1 wincent  staff    24 26 Aug 10:03 benchmark@ -> ../../packages/benchmark
lrwxr-xr-x    1 wincent  staff    21 26 Aug 10:03 client@ -> ../../packages/client
lrwxr-xr-x    1 wincent  staff    22 26 Aug 10:03 codegen@ -> ../../packages/codegen
lrwxr-xr-x    1 wincent  staff    21 26 Aug 10:03 common@ -> ../../packages/common
lrwxr-xr-x    1 wincent  staff    23 26 Aug 10:03 compiler@ -> ../../packages/compiler
lrwxr-xr-x    1 wincent  staff    22 26 Aug 10:03 graphql@ -> ../../packages/graphql
lrwxr-xr-x    1 wincent  staff    21 26 Aug 10:03 legacy@ -> ../../packages/legacy
lrwxr-xr-x    1 wincent  staff    20 26 Aug 10:03 lexer@ -> ../../packages/lexer
lrwxr-xr-x    1 wincent  staff    21 26 Aug 10:03 parser@ -> ../../packages/parser
lrwxr-xr-x    1 wincent  staff    21 26 Aug 10:03 server@ -> ../../packages/server
lrwxr-xr-x    1 wincent  staff    25 26 Aug 10:03 typescript@ -> ../../packages/typescript

Possibly related, I sometimes (rarely) see this, which indicates something is awry:

error TS5055: Cannot write file '/Users/wincent/code/masochist-experimental/packages/graphql/lib/document.d.ts' because it would overwrite input file.

error TS5055: Cannot write file '/Users/wincent/code/masochist-experimental/packages/graphql/lib/index.d.ts' because it would overwrite input file.

error TS5055: Cannot write file '/Users/wincent/code/masochist-experimental/packages/graphql/lib/lex.d.ts' because it would overwrite input file.

error TS5055: Cannot write file '/Users/wincent/code/masochist-experimental/packages/graphql/lib/parseDocument.d.ts' because it would overwrite input file.

Found 4 errors.

Why is it trying to treat those files as inputs and overwrite them?

That one seems to repro pretty reliably with yarn build --force.

wincent commented 1 year ago

Likely cause? Non-relative self-imports:

https://github.com/wincent/masochist/blob/0e5f68ffd4130d03643d9432709beef52329b29c/packages/graphql/src/parseDocument.ts#L7

https://github.com/wincent/masochist/blob/0e5f68ffd4130d03643d9432709beef52329b29c/packages/graphql/src/parseSchema.ts#L7

wincent commented 1 year ago

Fixed by https://github.com/wincent/masochist/commit/85989c875c45100522b3f0c862708832cf5dc4f4.