-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[🐞] Defining and calling $server() function inside onClick$ causes Error: Dynamic require of "_.js" is not supported #5495
Comments
OK, that is very bizarre. Thank you for a simple repro. |
Any update on this? |
the workaround is just to make sure the functions have $ wrap around them. looking at the build it looks like the server$ is not being output correctly in the server build. @mhevery this seems like an optimizer issue. will this be an issue in v2? I made my own repro repo with latest qwik |
@wmertens it looks like the server$ output is not working unless the handler is wrap in $ |
we probably use eslint to require $ if server$ (or any other $ is being used) for now. This works correctly with one server$ but once you have more than one then it breaks |
added this to the docs for now 48abd15 |
I missed this. This is still a problem in v2 I expect. |
yeah I'm fairly certain it's optimizer issue |
I have faced this issue on the production env at the version 1.5.6-dev20240611011722 |
Ok the reason is this: onClick$ will convert the handler to a noopQrl on the server because it can never be called. However, this happens before the handler is scanned for any other qrls, and so it misses the server$. The fix is therefore to still process noopQrls to check if there are any server$ calls in there. So I'm wondering if we should even support this, and if the eslint rule shouldn't be done instead? @mhevery ? |
@wmertens we should support this because calling server$ in onClick$ is used in all examples of server$ and it's the main use-case. Is there any way to process server$ before we convert to noopQrls or just have the optimizer convert everything to $ then it will work correctly? I think eslint is just a workaround until it's automated correctly |
Hi @PatrickJS , I just double checked the bug, it only happens when I define the server function inside When run So, I think using eslint or something to force the user to define the server function outside of |
status: this would be solved by #6871 combined with adding |
Which component is affected?
Qwik Runtime
Describe the bug
Hi,
I am defining a server function inside an
onClick
event handler and call it below the definition.In dev mode, everything works perfectly.
But in prod mode, I will get a POST error
POST http://localhost:4173/?qfunc=n4X1sOI0zW0 500 (Internal Server Error)
with error message sayingError: Dynamic require of "_.js" is not supported
.I was expecting no error, because dev mode works fine and what I did aligns with what Miško did in this video
I found a solution to this issue that might help finding the root cause or a fix.
Basically add another
$
to wrap the function assigned toonClick$
. But I guess this is not needed asonClick$
should be sufficient already, right? Anyways, hope this helps on debugging, thanks!Thanks!
Reproduction
https://stackblitz.com/edit/qwik-starter-qmzrws?file=src%2Froutes%2Findex.tsx
Steps to reproduce
npm run preview
System Info
Additional Information
No response
The text was updated successfully, but these errors were encountered: