Fixing TS2688: Cannot find type definition file in node_modules

Viewed 12065

When running tsc, I am getting many TS2688: Cannot find type definition file for 'someLibrary' These libraries came from node_modules. I have tried to exclude node_modules and skipLibCheck in tsconfig, but none of them works for me. Any idea why is this happening?

Here's my tsconfig.json

{
  "ts-node": {
    "files": true,
    "emit": true,
    "compilerHost": true
  },
  "compilerOptions": {
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "target": "es2016",
    "sourceMap": true,
    "typeRoots" : ["./node_modules","./node_modules/@types"],
    "jsx": "react",
    "allowSyntheticDefaultImports": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "module": "commonJS",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
  },
  "exclude": [
    "node_modules"
  ]
}

1 Answers

The problem was the wrong typeRoots. Should use the default ./node_modules/@types

Related