Skip to content

"Class constructor [XXX] cannot be invoked without 'new'" when using extend in ES6+ env #2101

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

Closed
RexSkz opened this issue Apr 30, 2025 · 3 comments · Fixed by #2103
Closed

Comments

@RexSkz
Copy link

RexSkz commented Apr 30, 2025

Root Cause

The code https://github.com/immutable-js/immutable-js/blob/main/src/methods/merge.js#L27-L33 calls constructor without new. If the constructor is a class, it will throw this error.

Playground: https://immutable-js.com/play/#Y2xhc3MgTXlSZWNvcmQgZXh0ZW5kcyBSZWNvcmQoewogIC8vIGE6IDEKfSkge30KCnZhciBteVJlY29yZCA9IG5ldyBNeVJlY29yZCgpOwpteVJlY29yZC5tZXJnZSh7IGE6IDQgfSk7

Image

Workaround

Do not use the empty object as the parameter of Record.

- class MyRecord extends Record({}) {}
+ class MyRecord extends Record({ a: 1 }) {}
@jdeniau
Copy link
Member

jdeniau commented May 5, 2025

Thank you for your report and for the playground link, I will investigate that !

@jdeniau
Copy link
Member

jdeniau commented May 5, 2025

Thanks, this has been released in 5.1.2

@RexSkz
Copy link
Author

RexSkz commented May 5, 2025

Wow, what a quick fix!

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

Successfully merging a pull request may close this issue.

2 participants