Skip to content

Cannot import d.ts files that are located in node_modules through tsconfig.json #12334

Closed

Description

TypeScript Version: Version 2.0.3

Code
ts-bug.zip

This is the tsconfig.json file:

{
    "compilerOptions": {
        "module": "commonjs",
        "target": "es5",
        "noImplicitAny": false,
        "sourceMap": false,
        "outDir": "dist"
    },
    "include": [
        "src/**/*.ts",
        "node_modules/monaco-editor/monaco.d.ts"
    ]
}

This the index.ts file:

new monaco.Test();

This the monaco.d.ts file, both in node_modules/monaco-editor and node_modules2/monaco-editor:

declare module monaco {
    export class Test {}
}

Expected behavior:
Running tsc should not report any errors.

Actual behavior:
Tsc says:

src/index.ts(2,5): error TS2304: Cannot find name 'monaco'.

If the tsconfig.json file is changed to the following:

{
    "compilerOptions": {
        "module": "commonjs",
        "target": "es5",
        "noImplicitAny": false,
        "sourceMap": false,
        "outDir": "dist"
    },
    "include": [
        "src/**/*.ts",
        "node_modules2/monaco-editor/monaco.d.ts"
    ]
}

... it compiles without any errors as expected.
So, for some reason, d.ts files in the node_modules folder are ignored when imported through tsconfig.json. However, when importing the file via /// <reference ... it works in both cases.

Activity

  1. mhegazy commented on Nov 17, 2016

    @mhegazy
    Contributor

    The issue here is the implicit exclude list that the compiler adds if one is not defined. the list by default is ["node_modules", "bower_components", "jspm_packages", <outDir>]. so even after it included your file "node_modules2/monaco-editor/monaco.d.ts" it excluded it because it was under node_modules.

    The workaround is to add an empty exclude list.

    We will need to change the behavior here to make sure we do not add an exclude list if an include list is available.

  2. ghost closed this as completedin #12350on Nov 21, 2016
  3. modified the milestones: TypeScript 2.2, on Dec 5, 2016
  4. locked and limited conversation to collaborators on Jun 19, 2018
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

    BugA bug in TypeScript

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions