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

index.ts error in circular dependencies #21225

Closed
JulioJu opened this issue Jan 17, 2018 · 2 comments
Closed

index.ts error in circular dependencies #21225

JulioJu opened this issue Jan 17, 2018 · 2 comments
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@JulioJu
Copy link

JulioJu commented Jan 17, 2018

This bug is with typescript 2.7.0-dev.20180116 or with typescript 2.6.2.

I thought is a node bug, so I've already report the bug at nodejs/node#18185. I've tried with Node.js 6.12.3 or 9.4.0. I've tried on Linux 4.14.13-1-ck x86_64.

  1. Unzip the zip file below
    strangeErrorIndexDotTs.zip.

In app/index.ts you could see the code at line 4 and 5

export * from './simple.module';
export * from './myclass';

./myclass is only a declaration of class: (

export class MyClass {}

In sample.module.ts we have:

import { MyClass } from './';
export function SimpleFunction() {console.log(new MyClass());}; // works
export const SimpleModule = console.log(new MyClass()); // Doesn't work

And in server.ts we have:

import { MyClass, SimpleModule, SimpleFunction } from './';
console.log(SimpleFunction); // works
console.log(new MyClass()); // works
console.log(SimpleModule); // Doesnt work
  1. npm install && node node_modules/typescript/bin/tsc
    We could see in appJS/index.js than at line 9 and 10 we have:
__export(require("./simple.module"));
__export(require("./myclass"));
  1. node appJS/server.js
    You could see the error:
.................../strangeErrorIndexDotTs/appJS/simple.module.js:7
exports.SimpleModule = console.log(new _1.MyClass()); // Doesn't work
                                   ^

TypeError: _1.MyClass is not a constructor
    at Object.<anonymous> (................/strangeErrorIndexDotTs/appJS/simple.module.js:7:36)
    at Module._compile (module.js:660:30)
    at Object.Module._extensions..js (module.js:671:10)
    at Module.load (module.js:573:32)
    at tryModuleLoad (module.js:513:12)
    at Function.Module._load (module.js:505:3)
    at Module.require (module.js:604:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (.................../strangeErrorIndexDotTs/appJS/index.js:9:10)
    at Module._compile (module.js:660:30)
  1. In app/index.ts replace line 4 by line 5 and line 5 by line 4.
    You should have :
export * from './myclass';
export * from './simple.module';
  1. rm -R appJS && node node_modules/typescript/bin/tsc :
    You could see in appJS/index.js than lines 9 and 10 are reversed:
__export(require("./myclass"));
__export(require("./simple.module"));
  1. node appJS/server.js: it works.

In the original project (see 1.) we could see than:

  • console.log(new MyClass()); in server.ts works (contrary to the same code in simple.module.ts).
    * In simple.module.ts: export function SimpleFunction() {console.log(new MyClass());}; works contrary to export const SimpleModule = console.log(new MyClass());
@mhegazy
Copy link
Contributor

mhegazy commented Jan 17, 2018

The compiler makes no grantees in the face of circular imports. seems like you are trying to import MyClass thought a cycle, and the result is undefined.

@mhegazy mhegazy added the Working as Intended The behavior described is the intended behavior; this is not a bug label Jan 17, 2018
@JulioJu JulioJu changed the title index.ts error when first export('file.name') have a dot. index.ts error in circular dependencies Jan 18, 2018
@JulioJu
Copy link
Author

JulioJu commented Jan 18, 2018

Ok I know. It's a mistake on my part. Sorry @mhegazy ! So I close this issue. It could be deleted ! 

@JulioJu JulioJu closed this as completed Jan 18, 2018
@microsoft microsoft locked and limited conversation to collaborators Jul 3, 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

2 participants