Skip to content

Using a library that has both ts and d.ts files in the same folder causes issues #10704

Closed
@ronzeidman

Description

@ronzeidman

TypeScript Version: all

Code
importing files, for example

import 'reflect-metadata/Reflect.js';

causes the following exception in tsc:

error TS6059: File 'client/node_modules/reflect-metadata/Reflect.ts' is not under 'rootDir'
 'client/src'. 'rootDir' is expected to contain all source files.

the tsconfig.json looks like this:

{
    "compilerOptions": {
        "declaration": false,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "module": "commonjs",
        "moduleResolution": "node",
        "noEmitOnError": true,
        "noImplicitAny": false,
        "rootDir": "./src",
        "sourceMap": true,
        "target": "es5",
        "outDir": "dist/"
    },
    "files": [
        "src/bootstrap.ts"
    ]
}

Expected behavior:
Suggestions:

  1. don't try to recompile .ts files not under rootDir if there is a js file there (if there isn't throw the same exception)
  2. don't try to recompile .ts files under node_modules folder unless there is no js file there
  3. don't compile excluded files even if referenced (that way you can use both "files" and "excluded" in the tsconfig.
  4. some configuration like compileDependencies: 'true'/['specific-dependency1', 'dep2']/false
    Actual behavior:
    tries to recompile everything even if it's from node_modules folder and even if I don't directly reference the .ts file and reference the .js file instead
    workaround 1: reference the.d.ts file instead of the .js file (doesn't work if the module itself has dependencies)
    workaround 2: put the .ts and the .d.ts+.js files in a different folder in the library but it's not possible for existing libraries since they are provided by a third party.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions