Skip to content

Conversation

@zdima40
Copy link

@zdima40 zdima40 commented Aug 2, 2025

Problem:
If you install a third-party library in a server project that pulls dependencies, then when you run ts compilation, errors may occur if these dependencies do not have type declarations.

For example, if you install the rimraf library, then when compiling npx tsc, we will see errors:

error TS2688: Cannot find type definition file for '@isaacs'.
The file is in the program because:
Entry point for implicit type library '@isaacs'

error TS2688: Cannot find type definition file for 'color-convert'.
The file is in the program because:
Entry point for implicit type library 'color-convert'

error TS2688: Cannot find type definition file for 'color-name'.
The file is in the program because:
Entry point for implicit type library 'color-name'

error TS2688: Cannot find type definition file for 'cross-spawn'.
The file is in the program because:
Entry point for implicit type library 'cross-spawn'

error TS2688: Cannot find type definition file for 'eastasianwidth'.
The file is in the program because:
Entry point for implicit type library 'eastasianwidth'

error TS2688: Cannot find type definition file for 'isexe'.
The file is in the program because:
Entry point for implicit type library 'isexe'

error TS2688: Cannot find type definition file for 'shebang-command'.
The file is in the program because:
Entry point for implicit type library 'shebang-command'

error TS2688: Cannot find type definition file for 'which'.
The file is in the program because:
Entry point for implicit type library 'which'

error TS2688: Cannot find type definition file for 'wrap-ansi-cjs'.
The file is in the program because:
Entry point for implicit type library 'wrap-ansi-cjs'
Reason: Errors occur because the tsconfig.json file has to specify the path "typeRoots": ["./node_modules"]. But we need to specify this path so that the main script recognizes types from the nkruntime namespace.

Solution:
Create, for example, a directory types in the root of the project, create a directory nkruntime in it, and move the file with types index.d.ts to it.

This approach will allow you to specify the path for specific types "typeRoots": ["./node_modules/nakama-runtime/types"] in tsconfig.json and avoid errors from third-party libraries.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@novabyte
Copy link
Member

novabyte commented Aug 7, 2025

@zdima40 My knowledge of the Type definition resolver is a bit limited so appreciate a bit more detail from you on why this change is needed. How can it be that we need to move where we place our Type definitions because it will affect how another library's definitions are resolved?

@zdima40
Copy link
Author

zdima40 commented Aug 8, 2025

@novabyte To the best of my knowledge, by default (when typeRoots isn't specified), TypeScript looks for type definitions in ./node_modules/@types. However, when typeRoots is explicitly specified, TypeScript ignores all default paths and only uses the specified ones.

From the error messages, it appears that type checking is performed in every subdirectory within the directories listed in typeRoots. When types are missing in these subdirectories, it leads to TypeScript errors. This situation occurs, for example, when installing the rimraf library, which installs its own dependencies that apparently lack type definitions.

By moving the type definition file, we limit the scope of type checking. An even better solution might be to additionally include ./node_modules/@types in typeRoots, meaning specifying two paths:

"typeRoots": ["./node_modules/@types", "./node_modules/nakama-runtime/types"]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants