Typescript Compiler doesn't exclude "node_modules" folder

Hi,

I'm working on an Angular 2 app with phpStorm, but what is really frustrating is that the TS compiler always keeps looking for errors in the "node_modules" folder as well and throws errors of course.

I have a tsconfig.json file where "node_modules" is being excluded, this is also set in the settings with phpStorm

So I don't get it why the TS compiler still keeps giving me these errors of stuff in my "node_modules" folder, I only want to see errors from my project, how can this be done?

12 comments
Comment actions Permalink

Hi Vlad,

I only have one tsconfig.json file, it located in my root directory of my project. It's pretty straight forward I think.

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

In my case, I do have imports to certain files of course, and I can understand that the TS compiler needs to read them, but it would be nice if the errors could be suppressed in some kind of way or made silent.  Now I have to scroll all the way down to see the errors I have made in my code, because the TS compiler will first show the errors of the node_modules files.

I understand why.. because the compiler imports those files first and then of course show the errors in the following order.

But bottomline.. this isn't really productive to work this way.

1
Comment actions Permalink

Please feel free to file a request for filtering the compiler errors. Related ticket: https://youtrack.jetbrains.com/issue/WEB-19064

1
Comment actions Permalink

Hi Elena,

That issue doesn't really relate to my problem. I don't have multiple tsconfig files, I just want to be able to filter certain messages that aren't in the scope of my project files.  Being folders / files located in the "node_modules" folder.

1
Comment actions Permalink

i didn't say it's your issue (and asked you to create a feature request), but it's definitely related, as this is a request to filter TSC output to show messages related to current file only

1
Comment actions Permalink

Hello,

What is your tsconfig.json?

Exclude patterns work fine for me. How many tsconfig.json files do you have in your project? Where are they located? Also, exclusion filters are not applied to files referenced (directly or indirectly) from included files. See https://github.com/Microsoft/TypeScript/issues/5509, https://youtrack.jetbrains.com/issue/WEB-19547#comment=27-1260307.

0
Comment actions Permalink

I have the same problem! 

{
"compileOnSave": false,
"compilerOptions": {
"target": "ES6",
"module": "system",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false,
"isolatedModules": true
},
"exclude": [
"node_modules",
"public",
"vendor"
]
}

 

IntelliJ IDEA 2017.1.2

Build #IU-171.4249.39, built on April 25, 2017
JRE: 1.8.0_112-release-736-b16 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Mac OS X 10.12.4

 

0
Comment actions Permalink

This seems to be an ongoing issue: https://youtrack.jetbrains.com/issue/WEB-24206.

Feel free to participate (vote/comment).

0
Comment actions Permalink

@Stevo, Idea seems to behave correctly: if the module is referenced from the source file, it's processed despite being excluded in tsconfig.json. And, as your files definitely do import @angular/core, the errors are shown. You will see the same errors when running tsc in terminal.

To make things clear: exclude is about the compiler automatically loading all files from your folder when you run tsc with no file list. This does not impact how import statements are resolved. if the compiler sees import * from "mod", it will try to find mod in node_modules and if it found it it will process it.

See http://www.typescriptlang.org/docs/handbook/tsconfig-json.html:

"Any files that are referenced by files included via the "files" or "include" properties are also included. Similarly, if a file B.ts is referenced by another file A.ts, then B.ts cannot be excluded unless the referencing file A.ts is also specified in the "exclude" list."

0
Comment actions Permalink

Is there an update on this? As Maartin said, this is a really unproductive way to work.

0
Comment actions Permalink

@Elena - So if I'm using a 3rd party library that does NOT enforce compilerOptions such as noImplicitAny or noUnusedParameters, there is no way for me to enforce those options ONLY within my own project? From what I currently understand these used to be linting options but now require type checking, and the proper way to enforce them is with compilerOptions.  The problem as you can see is that I can enforce linting options only for my code, but I cannot enforce them only for my own code using compilerOptions. 

0
Comment actions Permalink

@Jensbodal Please comment at https://youtrack.jetbrains.com/issue/WEB-24206 - that would be the best way to reach the developers and discuss this matter with them

0
Comment actions Permalink

Update on what, sorry? As I explained in https://intellij-support.jetbrains.com/hc/en-us/community/posts/206634839/comments/115000231764, the current behavior is expected and conforms to typescript compiler rules

-2

Please sign in to leave a comment.