-
Notifications
You must be signed in to change notification settings - Fork 105
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
Class is loaded twice on different pathes #231
Comments
I have same issue. I am using absolute import in one place and relative import in another place for class and instanceof is failing because of that: // httpError.ts
export class HttpError extends Error {...};
// foo.ts
import { HttpError } from '@errors'; // absolute import
export const foo = () => {
throw new HttpError(...);
}
// index.ts
import { HttpError } from './errors'; // relative import
try {
foo();
} catch(error){
console.log(error instanceof HttpError); // false
} |
Probably duplicate of this one |
Confirm, that is a critical issue for library. Cannot rely on instances anymore. Having non-unique singleton is critical. |
This solution helped me to fix my app for tsconfig-paths issue nestjs/nest#986 (comment) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Imagine you have a class X:
and a class Y:
tsconfig.json
Than
X
andY
load their own classSimpleService
. This is problematic, if you use dependency injection, i.e. withtsyringe
(@singleton()
), or other Constructor-relatedType
token things, because now the Typeclass SimpleService
just exists two times at runtime. I think it's not related totsyringe
, because the registration-key is just the class-Type. Other frameworks will fail similarly.If you either always use the relative imports or always the absolute imports, just one loaded class exists at runtime.
Hence
tsconfig-paths
is probably doing something wrong. Both imports must lead to same loaded class at runtime.The text was updated successfully, but these errors were encountered: