-
Notifications
You must be signed in to change notification settings - Fork 42
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
ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING error when using ESM script to render #160
Comments
It's not your logic, I noticed this error in a recent CI build. This library's logic is doing the bare-minimum, just calling I've found where the error is thrown in Node.js: https://github.com/nodejs/node/blob/0c460518e8c0728294cfbb5313d347a62856a2c5/lib/internal/modules/esm/utils.js#L89. When I have some time to investigate I will look into it, but it may be a while (several weeks). If you have spare bandwidth, it would be helpful if you could try creating a repro of the issue (without this library) and reporting the issue to the Node.js team if you manage to. In the meantime, |
I did try some simple reproductions by trying to import a mjs module from a script evaluated dynamically from the command line like the library does. However even when calling import multiple times, I did not get that error. So I have no idea what exactly triggers this and it does not seem to be a known problem in NodeJS. One simple workarround that works for me is just wrapping the MJS file in a CJS file like this:
One idea you might want to look into is changing the embedded scripts to be ESM as well and then specify the |
Okay, "script evaluated dynamically" meaning using --eval/-e? Do you mind cloning this repo, adding a test that reproduces the issue and creating a PR? Would be good to have a test case to debug against. I'm open to converting the embedded scripts to es modules, but will need some way to verify that doing so fixes the issue. |
I created a PR that reproduces the issue fairly reliable on my PC. However it seems that this only happens infrequently. So I had to do a lot of retries which makes the test very slow. One thing I noticed in the test protocol though was that even before the exception occurs there are connection resets and retries with the error stating that the connection was closed by the remote host. That makes me wonder whether maybe the error does occur every time, but the library is not fast enough to read the error before the process crashes. Could that be possible? |
Thanks for the PR. With regard to the "connection closed" retries, dynamic imports are within a try-catch block. If the dynamic import error gets caught some of the time, I don't see how it could get past the try-catch block on other occasions. Imo it's likely some other error, but might be related? Either fatal (killing the process immediately) or uncaught error. I've just done some reading up, we should add:
to rule out uncaught errors. Should also check windows event viewer for any further information on fatal errors. Another thing we can do would be to simplify the HTTP server to its most basic (for invoking .mjs), see if that resolves the issue and add back stuff till we find the offending logic. For example, right now the server polls the .Net process every second ( If none of that resolves the issue, we'll have to look into Node.js, crash dumps, etc. Appreciate if you could start on investigations, will try when I have more time! |
Was just wondering if this was just me. Also getting the error after switching our Vite output to the modern
|
Hey @JeremyTCD - Have you had a chance to dig further into this issue?🙏
Have you been using this workaround in production @aKzenT? Any issues? |
Hello Daniel, I must apologize, as I haven't had the opportunity to work on
this library recently due to other commitments. I'm looking to bring in new
maintainers to help manage the project. If you, or anyone else, are
interested in this role, please don't hesitate to let me know.
… Message ID: ***@***.***
com>
|
So far I did not have any issues with this approach, but it is not in production yet. That being said, I did encounter the issue even during development when using ESM directly, so I'm feeling confident that the workarround works for now. A native solution would of course be nicer. |
Looked like a good solution, but I did a quick test of this approach, and ran into this error in my project:
The error is triggered by loading Since Vite 4.4.4, they are logging a warning that UPDATE: Solved the issue by changing the import, so it imports the |
I'm not that confident i .NET, but trying to get the project to run, and looks like it needs some |
Unfortunately I just encountered this issue on production even with the workarround of loading ESM from CJS :-( So it seems that ESM will not work correctly until the loader script is in ESM as well. @thebuilder did you figure out how to build the project? |
Which issue? I solved the CommonJS imports issue, by changing the import (to what it suggests in the error mesage). We are currently looking into running pure Node server alongside the .NET project, and having them communicate over localhost HTTP. |
I mean I got ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING exceptions even when using a CJS wrapper to import my ESM file. |
Looking at the JavaScript part of the project - Thinking it would make sense to replace the current basic Webpack bundle, with a Vite/Rollup solution. Vite will most likely handle the import correctly in the bundle it makes.
Modules are supported since Node 14 (currently the oldest supported version). |
I just created a PR to move the project to ESM. All unit tests are green and my own project also is able to run as before. I noticed @thebuilder you had the same idea and even switched to vite, which is a great idea. However I don't think your PR is complete as there are some pieces missing to make the whole pipeline ESM. Feel free to incorporate my changes in your branch and we can wait for for @JeremyTCD to decide if he is okay to switching to vite or if he wants to stay with webpack for now. What issues do you have with running the unit tests? Maybe I can help. I also created a PR to fix some unit tests problems I encountered. |
Cool - I'll do that. |
Thanks for the prs, I don't have access to a pc till Friday, so will merge
them then.
Moving to esm looks good.
About webpack > vite, my (admittedly superficial) understanding is that
vite's designed to serve sites on localhost during development, and uses
rollup under the hood when you build for production. Do we just use rollup
in our case?
…On Wed, 26 Jul 2023, 19:51 Daniel Schmidt, ***@***.***> wrote:
I just created a PR to move the project to ESM. All unit tests are green
and my own project also is able to run as before. I noticed @thebuilder
<https://github.com/thebuilder> you had the same idea and even switched
to vite, which is a great idea. However I don't think your PR is complete
as there are some pieces missing to make the whole pipeline ESM.
Feel free to incorporate my changes in your branch and we can wait for for
@JeremyTCD <https://github.com/JeremyTCD> to decide if he is okay to
switching to vite or if he wants to stay with webpack for now.
What issues do you have with running the unit tests? Maybe I can help. I
also created a PR to fix some unit tests problems I encountered.
Cool - I'll do that.
Issue with getting it to run, might be because I'm using a Mac with Rider.
I'm missing some of the .NET frameworks it expects.
—
Reply to this email directly, view it on GitHub
<#160 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACZQXCTZAPURH4U7XVI3DP3XSEADXANCNFSM6AAAAAAVTTZ5KY>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Vite is pretty flexible. It can be used to serve SPA applications, but it also has built in support for SSR - So using this, we can have it output files that are already optimized for Node rendering. With Vite, this command is all that's really needed, to bundle the TypeScript for Node. vite build --ssr ./Servers/OutOfProcess/Http/Http11Server.ts --outDir ./bin/Debug/ |
I was trying out my changes on Azure App Service and encountered an issue on how webpack transforms import statements. Basically it uses "import.meta.url" which is 'undefined' due to loading the script as a string instead of as a file. I'm not sure why it works locally. This might be due to a different node version. The vite code does not have this issue and is generally cleaner and much closer to the original code. So I would also suggest to use vite. I will update my PR to use vite based on your changes @thebuilder . Hopefully I can then do some more tests until Friday to confirm that the issue is gone for good. |
Use ESM instead of CJS. Potentially fixes #160
When trying to use a ESM script with the library I'm getting a ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING error on the line that dynamically imports the script.
This is the line from the Javascript.NodeJS library minified script that causes the exception:
The script with "mjs" extension looks very simple:
The strange thing is also that initially it does seem to work, so some calls are successful, but then it stops working with that error.
Any ideas?
I'm using node 19.7.0 and 7.0.0-beta3 of this library.
The text was updated successfully, but these errors were encountered: