Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem when using 'index.ts' with 'outDir' and 'node' module resolution #17648

Closed
wrager opened this issue Aug 7, 2017 · 3 comments
Closed
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@wrager
Copy link

wrager commented Aug 7, 2017

With "moduleResolution": "node" compiler option, the import paths in JavaScript output for 'outDir' and 'outFile' options differs. I expected to see that the path of import { Rectangle } from './Shapes'; transforms to './Shapes/index'. However, I see '/index' at the end of Rectangle import path only if I use the 'outFile' option, not 'outDir'. Is this behavior expected or it is a bug in the typescript compiler?

TypeScript Version: 2.5.0

Code

/* tsconfig.json */
{
  "compilerOptions": {
    "module": "system",  // Or any other
    "moduleResolution": "node",

    "outDir": "./dist",
    //"outFile": "./dist.js",
  },
  "include": [
    "lib/**/*.ts"
  ]
}
/* /lib/Shapes/index.ts */
export { Rectangle } from './Rectangle';

/* /lib/Shapes/Rectangle.ts */
export class Rectangle {

}

/* /lib/Drawer.ts */
import { Rectangle } from './Shapes';

class Drawer {
    public constructor() {
        const rectangle: Rectangle = new Rectangle();
    }
}

Expected behavior:

/* /dist/Drawer.js (outDir) */
// system:
System.register(["./Shapes/index"], function (exports_1, context_1) {
// or amd:
define(["require", "exports", "./Shapes/index"], function (require, exports, Shapes_1) {
// or commonjs/umd:
var Shapes_1 = require("./Shapes/index");
// or es6/es2015/esnext:
import { Rectangle } from './Shapes/index';
/* /dist.js (outFile) */
// system:
System.register("Drawer", ["Shapes/index"], function (exports_3, context_3) {
// or amd:
define("Drawer", ["require", "exports", "Shapes/index"], function (require, exports, Shapes_1) {

Actual behavior:

/* /dist/Drawer.js (outDir). There aren't '/index' at the end of import paths. */
// system:
System.register(["./Shapes"], function (exports_1, context_1) {
// or amd:
define(["require", "exports", "./Shapes"], function (require, exports, Shapes_1) {
// or commonjs/umd:
var Shapes_1 = require("./Shapes");
// or es6/es2015/esnext:
import { Rectangle } from './Shapes';
/* /dist.js (outFile). Identical to the one we expect. */
// system:
System.register("Drawer", ["Shapes/index"], function (exports_3, context_3) {
// or amd:
define("Drawer", ["require", "exports", "Shapes/index"], function (require, exports, Shapes_1) {
@aluanhaddad
Copy link
Contributor

The compiler should not be rewriting the imported module path regardless of whether or not you are using --moduleResolution node and regardless of whether you are using --ourDir or --outFile.

If you are using SystemJS, you need to specify that Shapes uses the index file convention popularized by Node.

SystemJS.config({
  packages: {
    Shapes: {
      main: "index"
    }
  }
});

@mhegazy mhegazy added the Working as Intended The behavior described is the intended behavior; this is not a bug label Aug 21, 2017
@mhegazy
Copy link
Contributor

mhegazy commented Aug 21, 2017

see #16088 for more details.

@mhegazy
Copy link
Contributor

mhegazy commented Sep 5, 2017

Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

@mhegazy mhegazy closed this as completed Sep 5, 2017
@wrager wrager changed the title Problem when using 'index.ts' with 'outDir' and 'node' module relosution Problem when using 'index.ts' with 'outDir' and 'node' module resolution Sep 27, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

3 participants