Closed Mnib closed 3 months ago
Regarding the error you received Exception generated by QuickJS
that is a stub error.
QuickJS actually throws a more detailed error but you need to retrieve the details from the context. This can be done with CatchResultExt::catch
. This will give you a more detailed error message with what exactly is going wrong, and might also give me a better indication of what is going wrong.
Hello,
The error returned by catch
is the following:
Error:[eval_script]:2:15 expecting '('
at eval_script:2:15
So it looks like the error lies here:
import { a } from './a.js';
^
I guess this would mean that the
import something from 'some-file.js';
syntax is not supported.
The supported syntax would be:
const { a } = await import('./a.js');
Am I Correct?
Thanks
That is partially correct, import { ... } from 'foo'
is only supported in modules not in scripts. Ctx::eval
runs the javascript as a script. The import syntax should work if you instead use Module::evaluate
to execute the js as a module.
Understood!
Thanks for the help, I am closing this issue
Hi, I am currently working on a Rust project that needs to run JS scripts. However I am unable to load other JS modules.
Here is a minimal example:
a.js
looks like this:Here are the dependencies and version used:
What is happening:
ctx.eval
fails and returnsException generated by QuickJS
.What is expected:
Module loading normally
Workarount:
Using
await import(<FILE_PATH>);
works well.Am I missing something?
Thanks in advance