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

Cannot instantiate class directly from module.__get__ #142

Open
justinlovinger opened this issue Jun 29, 2018 · 0 comments
Open

Cannot instantiate class directly from module.__get__ #142

justinlovinger opened this issue Jun 29, 2018 · 0 comments

Comments

@justinlovinger
Copy link

justinlovinger commented Jun 29, 2018

Description

TypeError: Class constructor … cannot be invoked without 'new' is thrown when attempting to instantiate a class directly from module.__get__. However, if the class is first bound to a local variable, such as MyClass = module.__get__('MyClass'), the class can be instantiated.

Reproduction

hasclass.js

class Foo {

}

dorewire.js

const rewire = require('rewire');
const hasclass = rewire('./hasclass.js');

// No error when class if first bound to a local variable
const Foo = hasclass.__get__('Foo');
const foo1 = new Foo();

// Throws error if class is not bound to a local variable
const foo2 = new hasclass.__get__('Foo')();

Context:

  • Library version: 4.0.1
  • Environment: Windows
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