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

Script Setup - Class constructor [class] cannot be invoked without 'new' #6483

Closed
alexbot89 opened this issue Aug 16, 2022 · 5 comments
Closed

Comments

@alexbot89
Copy link

alexbot89 commented Aug 16, 2022

Vue version

3.2.37

Link to minimal reproduction

https://sfc.vuejs.org/#eNp9kMtOw0AMRX/FGiGlldrMvgRE1Q0fwHI26cSBlMxDHqcFRfl3nAelAond+F7Psa97tY8xP3eodqpIlprIkJC7+Gh842Ighh4IaxigpuAgk9bsar1g4kNbprSYuWZR7Kjkp5TdG1/oGSo4KRhdbEtGqQCKY8ccPDzZtrHvD0bdoWt4lbnPScg24PHyM2K1Xhs1fQR4xrYNE0PPENELmb3Q1UbNC25dGWWR4CVdP/abxUhG7WBSRk0yjbVRb8wx7bROtR1vckp5oFctr5w6z43DHJPbHilcEpKAjdrcMLSIZ6Qtoa+QkP5j/mr9wx2xg/GDRLk9qeTAj+n0FdZl1zJMDuyr6hCcK301p7LBJ6bOcqDV+hr0mzl8ARwjrgw=

Steps to reproduce

  1. Open link to SFC Playground
  2. Click the button
  3. An error Class constructor [class] cannot be invoked without 'new' is raised

What is expected?

No error should be visible in <script setup> as the the equivalent behavior is already working in <script>

What is actually happening?

The code is raising an error Class constructor [class] cannot be invoked without 'new' is raised

System Info

No response

Any additional comments?

See Discussion: #6480

@LinusBorg
Copy link
Member

LinusBorg commented Aug 16, 2022

The compiler produces this code:

(_ctx.$emit('myclick', new _unref(TestClass)())

which is invalid. This should be fixable with an additional set of paranthesis if we need to unwrap directly after new:

(_ctx.$emit('myclick', new (_unref(TestClass))())

@reitowo
Copy link

reitowo commented Jul 31, 2023

Guys, any update on this?
@yyx990803 It seems multiple same issues happens nowadays, and it is not a rare case, can you reevaluate this issue?

@simonrenoult-ra
Copy link

simonrenoult-ra commented Nov 8, 2023

Any update on this issue? Does that mean one should avoid using classes within script/setup? Is there a workaround?

@plabiausse
Copy link

plabiausse commented Dec 29, 2023

Is it possible to have a follow up on this issue ? The fact that it impacts only the code pushed in production, and not the code in dev mode is especially hurting :'(.

For reference I've been bitten by it both for bindings :var="new Test()" and triggers @click="test = new Test()"

It is sometimes lighter and more readable to be able to new something directly in the template, but if it is not working in production I would largely prefer to break things in my IDE, rather than having to patch some production code somewhere.

mbrown1413 added a commit to mbrown1413/Mechanical-Puzzle-Studio that referenced this issue Jan 11, 2024
Fixes an error when adding an item (piece or problem) because of an
error when using `new` inside an event handler.

See: vuejs/core#6483
@github-actions github-actions bot locked and limited conversation to collaborators Jan 19, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
7 participants