38
{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "noImplicitAny": false
  },
  "exclude": [
    "node_modules",
    "typings/main",
    "typings/main.d.ts"
  ]
}

I'm trying to upgrade an angular2/beta8 app to RC1, and I'm doing so by basically restructuring according to the Quickstart guide.

I copied its tsconfig.json into my project directory. I think I've got everything else ready,but when I run tsc, I get all kinds of errors within files in my node_modules folder. Why is it even looking in there in the first place?

Alex Kibler
  • 4,674
  • 9
  • 44
  • 74

4 Answers4

41

Add this option in tsconfig.json

{
  "compilerOptions": {
    "skipLibCheck": true
  },
}
Niko
  • 813
  • 8
  • 11
10

I don't know if you found an answer to this Alex but the referred to question/answer in the comments by LDL provides an answer, submitted by Srikanth Injarapu.

Here's the answer just in case someone doesn't feel like going to that link:

If you're targeting ES5, add "node_modules/typescript/lib/lib.es6.d.ts" to tsconfig.json file :

 {    
   "compilerOptions": {
     "module": "commonjs",
     "target": "es5",
     "noImplicitAny": false,
     "outDir": "built",
     "rootDir": ".",
     "sourceMap": false
   },
   "files": [
     "helloworld.ts",
     "node_modules/typescript/lib/lib.es6.d.ts"
   ],
   "exclude": [
     "node_modules"
   ]
 }

EDIT

In my application I make use of webpack to build my app and I still get the same errors being spat out on the console. I'm currently looking in to fixing this and will report back with what I find.

Community
  • 1
  • 1
Katana24
  • 8,706
  • 19
  • 76
  • 118
  • Pretty sure in 2019 the solution is to add `"lib": ["es6"],` to `compilerOptions`. – jedmao Aug 08 '19 at 22:03
  • No, adding `"lib": ["es6"],` didn't work for me. The original answer did, though. – eega Nov 02 '19 at 18:57
  • 1
    for Webpack 4.43.0 you only need: ```javascript "files": [ "src/index.ts", "node_modules/typescript/lib/lib.es6.d.ts" ] ``` Where src/index.ts is one of my entries. – danilo Jul 02 '20 at 17:16
2

For anybody using webpack, adding the "exclude" property did not work for me.

Instead adding all file extensions to the webpack "resolve" property and exclude node_modules from any "rules" objects worked:

resolve: {
    extensions: ['*', '.ts', '.tsx', '.js']
},
module: {
     rules: [
            {
               test: /\.ts(x?)$/,
               exclude: /node_modules/,
               use: [
                    {
                        loader: "ts-loader"
                    }
               ]
             },
             // All output '.js' files will have any sourcemaps re-processed by 'source-map-loader'.
             {
                enforce: "pre",
                test: /\.js$/,
                exclude: /node_modules/,
                loader: "source-map-loader"
             },
           ]
P Fuster
  • 2,224
  • 1
  • 20
  • 30
0

i have resolve this issue by npm updating global typescript packge

npm update -g typescript

then you can delete your tsconfig and create a new tsc --init