Reputation: 33
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:
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 except class_b.ts, using the following compiler invocation:
tsc --module commonjs class_a.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.
I'm using tsc 1.4.1.0.
Anything obvious I'm missing, here?
Upvotes: 3
Views: 12744
Reputation: 275857
I can verify that this is indeed a bug:
C:\Users\basaratsyed\Downloads\ts\fancyimport\first\second>node "C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.4\tsc.js" --module commonjs class_b.ts
../../third/class_c.ts(1,25): error TS2307: Cannot find external module '../first/shared'.
That said it does not show up in the language service API e.g. atom-typescript which is probably why it hasn't been reported yet:
Note : I've reported it here : https://github.com/Microsoft/TypeScript/issues/2193
Upvotes: 3