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

Bug: TypeError: Class constructor TextNode cannot be invoked without 'new' #5647

Closed
The-Code-Monkey opened this issue Feb 22, 2024 · 11 comments

Comments

@The-Code-Monkey
Copy link

The-Code-Monkey commented Feb 22, 2024

I get this error after compiling my wrapper code so that I can use the same editor on multiple projects easily.

So i followed this example: https://lexical.dev/docs/concepts/serialization#handling-extended-html-styling

which is what seems to be causing the issue.

https://github.com/The-Code-Monkey/TechStack/blob/main/packages/lexical/src/index.tsx#L54

Lexical version:

Steps To Reproduce

  1. import @techstack/lexical into a repo
  2. after adding it you get this error

Link to code example:

https://codesandbox.io/p/sandbox/nice-microservice-yq586s?file=%2Fsrc%2Findex.js

The current behavior

There is an error

The expected behavior

Either something is wrong with the docs or the Lib needs updating as it should replace the element

@acywatson
Copy link
Contributor

acywatson commented Feb 22, 2024

I suspect this is your problem: https://stackoverflow.com/questions/51860043/javascript-es6-typeerror-class-constructor-client-cannot-be-invoked-without-ne

Have you tried targeting a later version of javascript in your transpilation? Or is there a reason why you need to target es6?

@The-Code-Monkey
Copy link
Author

My tsconfig is targeting esnext not es6

@The-Code-Monkey
Copy link
Author

Also it builds fine it's just when I use it in another package

@acywatson
Copy link
Contributor

acywatson commented Feb 22, 2024

My tsconfig is targeting esnext not es6

Ah, I see - I missed the base config you extended.

Also it builds fine it's just when I use it in another package

I'd expect the transpilation to work fine, anyway. You'd see a runtime error (which is what you're seeing, right?).

Do you think you could provide a stack trace? I can't repro this in the playground with the same setup (another thing pointing to an environment/build issue).

@The-Code-Monkey
Copy link
Author

@acywatson I've posted a minimal reproduction using code sandbox issue happens there for me, anything that is currently on the GitHub link I sent is that package version that's in the code sandbox

@The-Code-Monkey
Copy link
Author

Another thing to note I have tested it locally using storybook and all is fine. All I can guess is that my rollup build command is breaking something but I wouldn't have thought so.

@acywatson
Copy link
Contributor

Hmm - one quick test could be to search the built files for "TextNode.call" and see if that's happening anywhere.

@The-Code-Monkey
Copy link
Author

The-Code-Monkey commented Feb 22, 2024

Hmm ok I'll try that tomorrow. It would be nice to see a working example of this sort of feature as even their own playground doesn't show this off

@The-Code-Monkey
Copy link
Author

@acywatson there is a textnode.call in the cjs built file but only within the extendedTextNode constructor where you would expect it to be.

I cannot find the same thing in the esm version.

@acywatson
Copy link
Contributor

@acywatson there is a textnode.call in the cjs built file but only within the extendedTextNode constructor where you would expect it to be.

I cannot find the same thing in the esm version.

I might be getting confused - should there be a TextNode.call? I think the whole source of the error is that TextNode is an ES6 class and therefore must be instantiated with new, as opposed to using Function.prototype.call.

@The-Code-Monkey
Copy link
Author

The-Code-Monkey commented Mar 1, 2024 via email

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

2 participants