Skip to content

typeRoots and types not working  #37708

Description

TypeScript Version: 3.8.3

Code
This is my tsconfig.json

{
    "compilerOptions": {
        "typeRoots": [
            "./typings"
        ],
        "types": ["Phaser"]  
    }    
}

In my project root, I got package.json, package-lock.json, main.ts(empty one), tsconfig.json.

tsconfig.json contains the above code.

typings folder which I wrote in typeRoots is empty.

After that, I run the following command in terminal:tsc --traceResolution

The idea is I am trying to use Phaser as a global variable in my main.ts file.

Bug 1)

Expected behavior:

What should happen is Phaser shouldn't get resolved because compiler should start looking into my custom folder typings.

Actual behavior:
Somehow it still gets resolved. And this is what it prints: Type reference directive 'Phaser' was successfully resolved to '/Applications/XAMPP/xamppfiles/htdocs/phaser-test/node_modules/Phaser/types/phaser.d.ts' with Pac kage ID 'phaser/types/[email protected]', primary: false. .

I don't know how it finds it since in my typeRoots, I don't have node_modules specified.

What I have tried:

I tried to exclude node_modules folder, I thought maybe they still get compiled and that's why this happens, but I couldn't make exclude work.

"exclude": ["node_modules/*"]

"exclude": ["./node_modules/*"]

"exclude": ["./node_modules"]

but none of these worked. , but i don't think that will help because i created one file test.ts and put something like this in there, but compilation is successful, So I guess the bug is related to typeRoots.

let a:number = 10;
a="gio";

Bug 2)

Let's change the above tsconfig.json to the following:

     "compilerOptions": {
        "typeRoots": [
            "./node_modules/phaser/types",
        ],
        "types": ["Phaser"]  
    },

What should happen now is Phaser should be resolved from ./node_modules/phaser/types and not take care of anything else such as trying to find package.json in node_modules/phaser and looking at types property in that package.json. But what actually happens is this doesn't get resolved at all on Ubuntu versions, since ubuntu is 'case-sensitive. This config works fine on OS x and windowsbecausePhasergets resolved fromnode_modules/phaser/package.json's types propertywhich shouldn't be happening because of mytypeRoots`.

Basically both things are so much related to each other.

Activity

  1. added 2 commits that reference this issue on Jul 22, 2020
    892f214
    e64e70f
  2. sheetalkamat commented on Jul 22, 2020

    @sheetalkamat
    Member

    This will probably be breaking change and will be part of broader work to improve type reference directive resolution

  3. 11 remaining items

  4. JesseRussell411 commented on Jul 20, 2022

    @JesseRussell411

    I'm working on a web app and have @types/node installed from a transient dependency. I have types set to an empty array in compiler options and it still uses the node types.

  5. maitlandmarshall commented on Aug 10, 2022

    @maitlandmarshall

    I'm working on a web app and have @types/node installed from a transient dependency. I have types set to an empty array in compiler options and it still uses the node types.

    I'm also experiencing the same problem.

  6. robertoms99 commented on Oct 28, 2022

    @robertoms99

    same problem with @types/node, I can use process.env in a client app

  7. added 4 commits that reference this issue on Dec 1, 2022
    182a133
    b5f2ae7
    1c2318d
    40bb75c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Fix AvailableA PR has been opened for this issueNeeds InvestigationThis issue needs a team member to investigate its status.RescheduledThis issue was previously scheduled to an earlier milestone

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions