Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular Typescript - exclude is not working in tsconfig.json

Currently I am facing issue with one of the modules inside node_modules while r compiling the Angular 4 Project and the getting the error as below hence I decided to exclude this project in the tsconfig.json but still I am getting the error, Can someone help me here

ERROR in D:/workspace/demo/node_modules/@types/d3-collection/index.d.ts (148,23): ',' expected.

ERROR in D:/workspace/demo/node_modules/@types/d3-collection/index.d.ts (483,40): ',' expected.

ERROR in D:/workspace/demo/node_modules/@types/d3-collection/index.d.ts (148,25): Type parameter name cannot be 'any'

Hence I decided to exclude the node_modules to avoid these errors but still I am facing the same error when running npm start

tsconfig.json

{
  "compilerOptions": {
    "declaration": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "lib": [
      "es6",
      "dom"
    ],
    "mapRoot": "./",
    "module": "es6",
    "moduleResolution": "node",
    "outDir": "../dist/out-tsc",
    "sourceMap": true,
    "target": "es5",
    "typeRoots": [
      "../node_modules/@types"
    ]
  },
  "exclude": [
    "**/node_modules/*"
  ]
}
like image 515
Mahesh G Avatar asked May 29 '18 16:05

Mahesh G


People also ask

What should I exclude in Tsconfig?

Use the exclude option in your tsconfig. json file to exclude a folder from compilation in TypeScript. The exclude option changes what the include setting finds and defaults to node_modules and bower_components .

What is include and exclude in Tsconfig json?

The include and exclude properties take a list of glob-like file patterns. The supported glob wildcards are: * matches zero or more characters (excluding directory separators) ? matches any one character (excluding directory separators)

What is the use of Tsconfig json file in TypeScript?

The presence of a tsconfig. json file in a directory indicates that the directory is the root of a TypeScript project. The tsconfig. json file specifies the root files and the compiler options required to compile the project.


1 Answers

you should add skipLibCheck it skips type checking of all declaration files (*.d.ts).

https://www.typescriptlang.org/docs/handbook/compiler-options.html

{
  "compilerOptions": {
    "declaration": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "lib": [
      "es6",
      "dom"
    ],
    "mapRoot": "./",
    "module": "es6",
    "moduleResolution": "node",
    "outDir": "../dist/out-tsc",
    "sourceMap": true,
    "target": "es5",
    "skipLibCheck": true,
    "types": ["d3-collection"]
  },
  "exclude": [
    "node_modules"
  ]
}
like image 85
John Velasquez Avatar answered Oct 20 '22 01:10

John Velasquez