Nest: Enums and decorators within modules are undefined outside of the module in which they are defined

Created on 30 May 2019  路  9Comments  路  Source: nestjs/nest

Bug Report

I have an AuthModule with a Role enum being exported in auth/index.ts. I also have an Authorized decorator saying which roles are allowed being exported in auth/auth.decorator.ts.

Current behavior

When I try to use the enum or the decorator to protect routes in the UserController in the UserModule, I get undefined compilation errors such Role has no property ADMIN.

Expected behavior

Ability to use the decorator and enum outside of the auth module.

Environment


Nest version: 6.2.4

needs triage

Most helpful comment

If I understand the issue correctly, it's not a bug in NodeJS, but rather a documented "feature". There's an open issue on TS about it.

All 9 comments

I can't find this behavior mentioned in the docs at all.

Don't use export * from './somefile.whatever.ts' and also the relative import will not work there, you need the full path, at least where the file is located.

I didn't know if that's a must, but when i face that issue and the DI goes crazy, i just use the full path, and it works.

Also i should mention that it only happens with guards and interceptors ?!

I think it's a bug in Typescript it self? IDK to be honest.

By the way, if it's a bug in Typescript, i think the docs should have a note about that.

Is there a bug in the TS repository I can refer to? Otherwise I will open one

Is there a bug in the TS repository ...

As i said I'm not sure of that 馃槄, I'm just guessing 馃槼

Alright. I am gonna open one then and see what happens. Thanks for your help. Your advice fixed my problem.

This could be related to a common issue in NodeJS where it caches module references as they get loaded.

@kowsheek is there a bug in the nodejs or v8 repos that I could refer to?

If I understand the issue correctly, it's not a bug in NodeJS, but rather a documented "feature". There's an open issue on TS about it.

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings