How to Fix: ts-node returns Typescript errors when tsc does not
/ 1 min read
Table of Contents
Context
Project building without errors with tsc
, same ts-config
sent to ts-node
but ts-node
raised Typescript errors.
Github issues found
Solution
The project recently had new module type definitions for npm modules which did not provide any as .d.ts
files.
tsc
knows about them already if they are in the tsconfig.json
include
property.
ts-node
does not load all these files listed in the tsconfig
automatically. But it will load explicitly mentioned type files in the typeRoots
or paths
compiler option.
To fix it, I added the folder where the modules’ types were defined in the compiler option typeRoots
:
{ // tsconfig.json // ...>8... "compilerOptions": { // ...>8... "typeRoots": [ "./node_modules/@types", "./src/@types" // <- The added types folder ] // ...>8... } // ...>8---}