Description
We use NPM packages for creating TypeScript libraries. This is great for TypeScript code which is used in multiple projects. We already use TypeScript 2.0 and since 20160701 there is a problem when compiling those sources. The index.ts
file in those packages is compiled, but the resulting index.js
is not emitted. Other dependencies in index.ts
(as in the example below) are emitted as expected. Only index.js
is missing. I think it should be possible to have NPM packages with just the TypeScript source files so you can use packages for shared code/libraries. This worked like a charm before 2.0.0-dev.20160701. Probably broken by #9459. Could be on purpose, but the behavior right now is not consistent. All sources are compiled and emitted, only the index.js
files are missing which is strange and results in a headache ;-).
TypeScript Version: 2.0.0-dev.20160701 (2.0.0-dev.20160630 gives the right output).
Code to reproduce
Create the following structure:
node_modules\test-module\index.ts
node_modules\test-module\something.ts
test.ts
With the following code:
// node_modules\test-module\something.ts
export const SomeString: string = "Hello world";
// node_modules\test-module\index.ts
export { SomeString } from "./something";
// test.ts
import { SomeString} from "test-module";
console.log(SomeString); // Should output `Hello world`
Expected behavior:
When compiling test.ts
the following files should be emitted:
node_modules\test-module\index.js
node_modules\test-module\something.js
test.js
Actual behavior:
The index.js
file is missing and the output is:
node_modules\test-module\something.js
test.js
If 2.0.0-dev.20160630 is installed the output is as expected.
I understand that in some cases it is not desirable to compile the code in the node_modules
folder. But in our case we emit the code to a outDir
specified in tsconfig.json
. As the complete source tree will be reflected to this outDir
also the node_modules
folder is created in the outDir
. Just as expected. We can use something like webpack or Browserify to bundle the code. We think this should be possible. Just pure TypeScript code in the NPM package and no need to publish the compiled JS in there...
Maybe it is better to have a compiler option to disable compiling sources under node_modules
so one can decide the desired behavior...