Skip to content

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

@hediet

Description

@hediet

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScript

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions