Closed
Description
TypeScript allows shorthand for importing the index.ts
file in a package. CommonJS does too.
However, this is not specified in ES2015 modules. Some loaders/bundlers support it (Rollup, Webpack) but some do not (Closure Compiler)
It would be more conservative to normalize these import locations to include the explicit /index
suffix for better compatibility.
Repro:
$ ./node_modules/.bin/tsc -v
Version 2.0.10
$ cat import_index.ts
import {a} from './one';
console.log(a);
$ cat one/index.ts
export const a = 1;
$ cat tsconfig.json
{
"compilerOptions": {
"target": "es5",
"experimentalDecorators": true,
"noImplicitAny": true,
"strictNullChecks": true,
"moduleResolution": "node",
"module": "es6",
"rootDir": "",
"declaration": true,
"lib": ["es6", "dom"],
"baseUrl": ".",
"types": []
},
"files": ["import_index.ts",
"node_modules/@types/node/index.d.ts"]
}
$ ./node_modules/.bin/tsc
$ cat import_index.js
import { a } from './one';
console.log(a);
The proposal is this should have been written as import { a } from './one/index';