Skip to content

pathMapping doesn't use rootDirs for absolute or mapped paths #7837

Closed
@alexeagle

Description

@alexeagle

Here's a mockup of our directory structure:

$ cat binary/some/other/project/bin-a.ts
export let a;
$ cat generated/path/to/my/project/gen-b.ts
export let b;
$ cat generated/spot/for/node/modules/angular2/core.d.ts
export let bootstrap;
$ cat path/to/my/project/c.ts
// NOTE: we don't use a relative path here because it's a walk up to the top of the source tree and back
import {a} from 'some/other/project/bin-a';
import {b} from './gen-b';
import {bootstrap} from 'angular2/core';

And tried to compile with

"compilerOptions": {
        "module": "commonjs",
        "target": "es5",
        "noImplicitAny": false,
        "sourceMap": false,
        "baseUrl": ".",
        "rootDirs": [
          "generated",
          "binary",
          "."
        ],
        "paths": {
          // NOTE: this assumes we'll resolve it under the "generated" root, to find the generated .d.ts file
          "angular2/*": ["spot/for/node/modules/angular2/*"]
        },
        "noEmit": true
    },

and I get

$ ./node_modules/.bin/tsc
path/to/my/project/c.ts(1,17): error TS2307: Cannot find module 'some/other/project/bin-a'.
path/to/my/project/c.ts(3,25): error TS2307: Cannot find module 'angular2/core'.

In Vlad's comment we see why:
#5039 (comment)

baseUrl / paths are used to resolve non-relative module names and rootDirs are applied only for relative names

Sorry we didn't notice this earlier. I believe @mprobst had verified our use cases against #2338 and then maybe the design changes before merge made this no longer work. I'm just now working to update google-internal to use this (we are also blocked on #7573 )

@mprobst please check if I've accurately represented the shape of imports that we want. @vladima I know this is close to release, so I wonder what our options are now. Could rootDirs be consulted for all resolutions, or did you eliminate that option in the design process?

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions