Skip to content

moduleNameResolver caches result for too many directories #26271

Closed
@ajafff

Description

@ajafff

TypeScript Version: 3.1.0-dev.20180807

Search Terms:

Code

git clone git@github.com:ajafff/ts-module-resolver-cache-bug.git
cd ts-module-resolver-cache-bug
mkdir -p sub/dir/node_modules && ln -fs ../../../node_modules/a sub/dir/node_modules/a
tsc -p .

Expected behavior:

Compiles without error.

Actual behavior:

Viewing ./sub/dir/foo.ts and ./sub/bar.ts in VSCode shows no error. That's probably because there is no caching involved.

Error in ./sub/bar.ts because the import of 'a' resolves to the wrong node_modules folder due to the cache bug.

This is caused by the cache computing the commonPrefix from resolvedFileName and not from originalPath. Therefore all directories up to CWD now have the cached result of ./sub/dir. The lookup of 'a' from ./sub also hits the cache although it should start its own lookup. This bug is only triggered if the files are processed in order (./sub/dir/foo.ts before ./sub/bar.ts).

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions