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

instanceof/constructor check fails if a class has different versions in node_modules #17943

Closed
yinrong opened this issue Jan 2, 2018 · 3 comments
Labels
module Issues and PRs related to the module subsystem. question Issues that look for answers.

Comments

@yinrong
Copy link

yinrong commented Jan 2, 2018

  • Version: any
  • Platform: any
  • Subsystem: not sure

suppose my runtime directory structure is

my_pkg_1/
my_pkg_1/node_modules
my_pkg_1/node_modules/[email protected]
my_pkg_1/node_modules/my_pkg_3/
my_pkg_1/node_modules/my_pkg_3/node_modules/
my_pkg_1/node_modules/my_pkg_3/node_modules/[email protected]

a check like

my_instance.constuctor === MyType

or

my_instance instanceof MyType

may fail since MyType may point to eigher [email protected] or [email protected]

I consider this may be a problem since I have experienced once during deploying process that it take quite a long time to find out the bug.

I have to remove all duplicate packages every time during deploying process. Another option of using peerDenpendencies is also not good enough I think. Should npm or node deal with this problem?

@bnoordhuis bnoordhuis added module Issues and PRs related to the module subsystem. question Issues that look for answers. labels Jan 2, 2018
@bnoordhuis
Copy link
Member

You probably won't be surprised the answer is 'no' - they're different functions and therefore construct different objects. npm can flatten node_modules up to a point but not if they're API-incompatible versions of the same module.

@yinrong
Copy link
Author

yinrong commented Jan 2, 2018

@bnoordhuis thanks for comment. any suggestion on how to compare types? I still think it's a pitfall considering the result. I suppose you mean it's normal behaviour for all programming languages.

@bnoordhuis
Copy link
Member

any suggestion on how to compare types?

My suggestion would be "don't" - they're different types, possibly with different properties and methods.

I'd work on getting all modules to agree on a single version (or compatible version range) of my_pkg_2 so that npm can deduplicate it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module Issues and PRs related to the module subsystem. question Issues that look for answers.
Projects
None yet
Development

No branches or pull requests

2 participants