Skip to content

Disable type checking for node_modules entirely #40426

Description

@gempir

Search Terms

skipLibCheck
node_modules
ignore library
exclude

Suggestion

Either a new option or the existing option skipLibCheck should be able to disable type checking for node_modules.

Use Cases

A library author might have a faulty import or might only provide typescript files for his library and not transpiled code. As a user of this library I want to be able to disable type checking for a library (or all) because I trust this library has been tested enough in other ways.

Another issue where I found a library shipping ts files and causing errors for the user: #15363

The response at the end is very relevant

I understand that libraries shouldn't publish *.ts files, but sometimes, they just do, and we can't control every other library easily.
I think typescript should not try to apply this kind of setting (here noImplicitAny) to the node_modules simply because it is meant to be applied to the user code being compiled, not the external dependencies.

Originally posted by Victor Noël (@victornoel) in #15363 (comment)

Examples

I had the case that a library came with a dist/ folder and almost all types were perfectly arranged in .d.ts files. But one file was making an import from ../index.d.ts(which seems to be for development purposes, the lib main file is dist/index.d.ts) which in turn then imported src/ClassA.ts

The library author used a different tsconfig and didn't use strict type checking, but I do and that's why the type check fails for me, because now the typescript source files of the library author are type checked.

Checklist

My suggestion meets these guidelines (in case of a new option):

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

Activity

  1. DanielRosenwasser commented on Sep 9, 2020

    @DanielRosenwasser
    Member

    As a user of this library I want to be able to disable type checking for a library (or all) because I trust this library has been tested enough in other ways.

    Okay, this is one of the reasons you might use skipLibCheck.

    I had the case that a library came with a dist/ folder and almost all types were perfectly arranged in .d.ts files. But one file was making an import from ../index.d.ts(which seems to be for development purposes, the lib main file is dist/index.d.ts) which in turn then imported src/ClassA.ts

    This is the opposite of the scenario you're describing. The library author has shipped incoherent types, and who's to say what the correct interpretation of that is? It is good that TypeScript errors here, even if it is an overall terrible user experience.


    "Disabling type-checking" can mean a lot of things. Having the package come in as any is one possibility. If that's what you're looking for, then you can add a single global file with declare module "incorrectly-authored-library"; until the package ships correct types. Otherwise, I'm not sure what you might have in mind.

  2. DanielRosenwasser commented on Sep 9, 2020

    @DanielRosenwasser
    Member

    I want to mention after reading this a second time: shipping .ts files is generally nice when using --declarationMaps but I don't know how to best address the issue of different settings between your project and the library's project. Figuring out good prescriptive advice for doing that might be one strategy here.

  3. gempir commented on Sep 9, 2020

    @gempir
    Author

    Yeah there are lots of good reasons to actually have the sources of a library available, I like to explore them in my IDE sometimes or maybe while debugging etc.

    But I don't actually want to have them checked by the typescript compiler, hence the skipLibCheck. It's just so confusing to me why the skipLibCheck is only intended for typing files and not for .ts files

  4. RyanCavanaugh commented on Sep 9, 2020

    @RyanCavanaugh
    Member

    This scenario is going to be completely busted for a lot of reasons. It seems like the option one would really want, if they found themselves stuck in it, would be to say that .ts files under some given paths should be treated as if they were .d.ts files (don't emit, don't typecheck under SLC, don't use to compute rootDir, etc) but have their implementations used for inference. That said, this is just critically a misconfiguration and it's possibly counterproductive to do gymnastics to make it work.

  5. gempir commented on Sep 10, 2020

    @gempir
    Author

    I think .ts files imported by .d.ts files should be treated the same way, so if skipLibCheck is enabled it should ignore them.

    If you are importing .ts files from actual source files like dist/main.js importing ../src/ClassB.ts then i just expect it to break. That shouldn't be ignored.

  6. shadow-light commented on Aug 19, 2021

    @shadow-light

    Could there be a way to just silence errors from certain paths?

    I don't want to make a whole import from node_modules type any as 99% of the types are fine and are useful for code completion, but I don't want to hear about the 1% of types that don't adhere to my tsconfig when I can't do anything about them (aside from fork the whole module for the sake of a couple of errors).

    Noting that a single type check fail would break CI unless I silence it some how.

  7. shadow-light commented on Aug 19, 2021

    @shadow-light

    (I tried @ts-ignore above the import with the issue, but the errors are with certain files in that imported module, so obviously didn't work)

  8. NonkelDaniel commented on Aug 20, 2021

    @NonkelDaniel

    I am having a very similar issue with a node_module that is included locally in package.json with a path: file:.... there are type errors happening inside of that library and the compiler does not ignore them despite having "skipLibCheck": true in the config.

  9. shadow-light commented on Aug 20, 2021

    @shadow-light

    I had the case that a library came with a dist/ folder and almost all types were perfectly arranged in .d.ts files. But one file was making an import from ../index.d.ts(which seems to be for development purposes, the lib main file is dist/index.d.ts) which in turn then imported src/ClassA.ts

    The library author used a different tsconfig and didn't use strict type checking, but I do and that's why the type check fails for me, because now the typescript source files of the library author are type checked.

    Just ran into this exact scenario trying to type check my build scripts. Seems like not many people do that so some build-related modules have issues that go unnoticed.

  10. shadow-light commented on Aug 20, 2021

    @shadow-light

    Here's an example of a project that seems to be doing something benign, simply importing an interface for the sake of type checking. But the import path points to distributed typescript source files rather than the compiled JS. And while there aren't any issues with the types of that module, because my project has stricter type check settings it causes issues.

    https://github.com/underfin/vite-plugin-vue2/pull/125/files

  11. 50 remaining items

  12. ibrust commented on Mar 19, 2025

    @ibrust

    I don't understand what the argument would be for not allowing the programmer to prevent type checking of node_modules. Honestly it is completely obvious that this should be supported.
    When you have people disabling strict type checking and the use of type declaration files your design idea isn't working. Instead of assuming people are incapable of using tools properly, assume they are intelligent and provide them the tools.

  13. hematy61 commented on May 13, 2025

    @hematy61

    Can't use verbatimModuleSyntax atm if even one package has a bad setup import

    I have the same issue. As soon as I turned on verbatimModuleSyntax, it started type checking dependencies.

  14. robpalme commented on May 13, 2025

    @robpalme

    Mo (@hematy61) Probably you have an unused import that was previously being trimmed via the default "Import Elision" behavior. VMS turns that off.

    If you trim it manually (delete the line, delete the binding, or mark the import/binding with type) then you should restore the original scope of the checker.

    After trying this, if you still find that VMS increases the scope of the checker, please provide a minal repro. Because I think that would be new information and potentially a bug.

  15. Hookyns commented on Jun 11, 2025

    @Hookyns

    Ryan Cavanaugh (@RyanCavanaugh)

    Can people post "Here's how I ended up importing .ts files from node_modules" or "Here are the errors in a .d.ts in node_modules I had" instead of "same" ?

    This is a real and easily reproducible problem. You're not intentionally importing TypeScript - you're simply installing a package that includes a .ts file listed under the types field in package.json. There are packages out there doing this, and the number is growing due to support for runtimes like Deno and Bun.

    Consider a package with the following package.json:

    package.json

    {
        "name": "incriminated-package",
        "types": "index.ts", // <==== this !!
        "module": "dist/index.js",
        "type": "module",
        "files": [
            "dist/index.js",
            "index.ts"
        ]
    }

    If that linked .ts file is less strict than your own codebase, you're in trouble. Why did someone publish a .ts file alongside the compiled JS instead of a .d.ts file? There are multiple reasons:

    • To support Deno, Bun, and other runtimes that natively use .ts.
    • It's sometimes impossible to generate .d.ts files due to limitations in certain bundlers. You might need specific plugins, and they don’t always work - especially with complex setups involving multiple exports, or when the folder structure of dist/ differs significantly from src/.

    DEMO here, live example here on stackblitz.

    Error:

    node_modules/incriminated-package/index.ts:2:5 - error TS2322: Type 'null' is not assignable to type 'string'.
    
    2     property: string = null;
          ~~~~~~~~
    
    
    Found 1 error in node_modules/incriminated-package/index.ts:2
    

    The TypeScript file is not used during compilation or at runtime - only the JavaScript is. I mean, that TS has no real impact on project but typechecking. So why does this error matter when skipLibCheck is enabled? TypeScript doesn’t use that code; it doesn’t bundle it or execute it in any way.

    Why can't it be ignored the same way .d.ts files are? If there's a valid scenario where it does matter, then maybe the solution is to introduce a separate config option - something like skipLibTsCheck?! It will not break anything and quite a lot of people want this for 5 years!

  16. somebody1234 commented on Jun 18, 2025

    @somebody1234

    another example of .ts files (advertently or not) being included in the types field which will cause errors in stricter codebases.

    (no hate to the authors! it's a good library)

  17. phil294 commented on Jun 28, 2025

    @phil294

    I'd also welcome it if we could ignore node_modules errors per se, and/or have skipLibCheck also skip non-node_modules .d.ts files is pretty annoying. But I also stumbled upon something else:

    I tried the suggested strategy outlined by Daniel, declare module 'whatever' to overwrite wrong typinges, but that doesn't if you're

    1. using JS, not TS, but strict type checking
    2. using jsconfig.json, not tsconfig.json
    3. pass the jsconfig.json to tsc using -p option
    4. the library ships as js files only

    Example: npm install vue-virtual-scroller, import it in a .js file, set strict: true in jsconfig.json, run npx tsc --noEmit -p jsconfig.json and see errors that are impossible to get rid off, regardless of any extra .d.ts files you put in the directory.

    I don't really know what's going on and the type check output seems also to be pretty different with jsconfig, but the solution is simple:

    Rename jsconfig.json to tsconfig.json.

    Maybe it's a bug. But my past experience in reporting bugs has been that everything is always working as intended and it's my misunderstanding at fault 😄. On an unrelated note though, it's so refreshing to see core TS contributors on GH issues debating with the community over and over and keep explaining and arguing even after years. This must be exhausting AF, but it's one of my favorite aspects about the language.

  18. repulsio commented on Jul 18, 2025

    @repulsio

    Any solution here? I just want to simply exclude a folder from types

  19. onyedikachi23 commented on Aug 29, 2025

    @onyedikachi23

    It's almost 5 yrs now. Ryan Cavanaugh (@RyanCavanaugh) Please 🙏 add the feature.

  20. iva2k commented on Sep 5, 2025

    @iva2k

    It is clear that without taking types from node_modules, all packages that have been used and provide return values into user code will be "disconnected" and lead to no type checking on the function calls, on returned types and derived values, which can be a lot.

    So it makes perfect sense to keep reading types from node_modules.

    What does not make sense is to bark at every type issue in packages in node_modules, which could be a huge pollutant of the logs.

    I sense that everyone coming to this issue simply wants to silence all the warnings and (maybe optionally) errors from node_modules, as they simply create a ton of noise, but are not actionable and not fixable (in a sense that 3rd party packages are not under user control).

    What if there were an option "silence node_module type check messages" with 3 choices - show all (errors and warnings), show only errors, and hide/ignore all errors and warnings. Regardless of that setting, types that can be used from the node_modules packages should propagate through the type checking process. The ones that are broken or not useable, will be quietly ignored if setting asks for it. Default, if not specified, of course, should be like it is currently behaving - report all issues, so there are no surprises.

  21. onyedikachi23 commented on Sep 5, 2025

    @onyedikachi23

    It is clear that without taking types from node_modules, all packages that have been used and provide return values into user code will be "disconnected" and lead to no type checking on the function calls, on returned types and derived values, which can be a lot.

    So it makes perfect sense to keep reading types from node_modules.

    What does not make sense is to bark at every type issue in packages in node_modules, which could be a huge pollutant of the logs.

    I sense that everyone coming to this issue simply wants to silence all the warnings and (maybe optionally) errors from node_modules, as they simply create a ton of noise, but are not actionable and not fixable (in a sense that 3rd party packages are not under user control).

    What if there were an option "silence node_module type check messages" with 3 choices - show all (errors and warnings), show only errors, and hide/ignore all errors and warnings. Regardless of that setting, types that can be used from the node_modules packages should propagate through the type checking process. The ones that are broken or not useable, will be quietly ignored if setting asks for it. Default, if not specified, of course, should be like it is currently behaving - report all issues, so there are no surprises.

    This is exactly what we need. Good reasoning.

  22. sparr commented on Nov 29, 2025

    @sparr

    Today I encountered the behavior that tsc insists in doing error checking for node_modules that publish .ts sources, even with node_modules excluded and skipLibCheck set. I would like a way to disable that behavior.

  23. Pentadome commented on Dec 8, 2025

    @Pentadome

    I needed to import a .ts file from a node module and now i get typescript errors from that file. Why can't we set paths where we don't want type checking?

  24. everett1992 commented on Feb 16, 2026

    @everett1992

    nodejs can run (some) .ts files natively, but it won't load .ts files from node_modules, based largely on arguments from the typescript team that if node allowed .ts files in node_modules folks would publish .ts only packages to npm, which could cause performance issues for tsc as processsing .ts files is slower than .d.ts, and introduces nuance of tsc version and tsconfig settings.
    Jake Bailey (@jakebailey) Ryan Cavanaugh (@RyanCavanaugh)
    I buy those arguments, but they convince me that typescript should implement this feature - not type checking .ts files in node_modules - not that node should support type stripping in node_modules.

    I setup a fresh tsc 5.9 project and wrote a module in node_modules/foo with .ts and .d.ts files, and typescript always preferred the .ts files instead of .d.ts files. TypeScript should have a recommended or default option to prefer .d.ts files, or ignore all .ts files in node_modules. That should fix the potential performance issue, and allow node to support type stripping in node_modules.
    Folks can ship libraries with .ts to run and .d.ts files for type checks.

    nodejs/typescript#14 (comment)
    nodejs/node#57215 (comment)

  25. added a commit that references this issue on Jul 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions