-
Notifications
You must be signed in to change notification settings - Fork 13k
Description
(Also posted on StackOverflow: https://stackoverflow.com/questions/28844917/typescript-cant-find-external-module-when-referenced-by-two-different-files)
I may be missing something obvious, but Typescript's module resolver for commonjs isn't working as expected.
Given the following directory structure and files:
- ./first/shared.ts
- ./first/second/class_a.ts
- ./first/second/class_b.ts
- ./third/class_c.ts
Where:
- class_a references shared.ts
- class_b references class_a.ts and class_c.ts
- class_c references shared.ts
Specifically:
shared.ts:
class Shared{}
export = Shared;
class_a.ts:
import Shared = require('../shared');
class A{}
export = A;
class_b.ts:
import A = require('./class_a');
import C = require('../../third/class_c');
class B {}
export = B;
class_c.ts:
import Shared = require('../first/shared');
class C {}
export = C;
All compile individually, except class_b.ts, using the following compiler invocation:
tsc --module commonjs class_b.ts
Compiling class_b.ts fails with the error that it can't find shared.ts:
../../third/class_c.ts(1,25): error TS2307: Cannot find external module '../first/shared'.
Note that if you reverse the order of imports in class_b.ts, you get a different error:
class_a.ts(1,25): error TS2307: Cannot find external module '../shared'.
It seems the compiler is finding shared.ts the first time it is imported, but not the second time.
This is with tsc 1.4.1.0.