Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.