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

Different import paths for same module resolve it to two different modules #119

Open
nsine opened this issue Apr 20, 2020 · 0 comments
Open

Comments

@nsine
Copy link

nsine commented Apr 20, 2020

Hey there 👋

TLDR;

I have created a small project to show the issue: https://github.com/nsine/tsconfig-paths-bug-example 🙂

Description:

  • We have configured custom-resolved paths ~/* -> ~/src in tsconfig.json
  • In file errors/classes.ts we define custom error class AppError which extends Error
  • And we throw it in moreCode/code.ts file in function runCode
  • errors/errorHanlder runs this function in try/catch and here is the issue:

If i'm trying to check if err instanceof AppError - i will get false, however i used this class when throwing. After that i initialize the Error line after and it has correct constructor and therefore instanceof works there.

Looking at produced compiled js I see that file errorHandler.js imports var classes_1 = require("./classes"); however code.ts has another import path var classes_1 = require("~/errors/classes"); (I expect it's correct behavior). But looking at this instanceof example I assume that these two imports resolve module classes.ts twice as two different modules which is incorrect 👯‍♂️

Will appreaciate any ideas how to fix that!

@nsine nsine changed the title instanceof doesn't work when using different kind of imports Different import paths for same module resolve it to two different modules Apr 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant