-
Notifications
You must be signed in to change notification settings - Fork 279
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
Embedder API: Loading ES6 Modules #3991
Comments
I tried a lot of ways, none of them worked so far. 1. SourceTextModuleI tried to use 2. vm.runInThisContext + dynamic importEnvironment is loaded using a custom callback: v8::MaybeLocal<v8::Value> loadRes = node::LoadEnvironment(env,
[this](const node::StartExecutionCallbackInfo& info) {
...
}); And then I use the v8::Local<v8::Value> source = v8::String::NewFromUtf8Literal(isolate, "import('path').then(p => console.log(p))");
runInContextFunc->Get(isolate)->Call(context, v8::Null(solate), 1, &source).ToLocalChecked(); This doesn't work and keep throwing an error: 3. LoadEnvironment without any callbackI tried to set a startup script to node::LoadEnvironment(_setup->env(), node::StartExecutionCallback{}); The script is executed properly, but I still can't easily use |
I don't know if it's the best idea, but I solved that using |
Related to nodejs/node#31234 to provide built-in implementations of module |
There has been no activity on this issue for 11 months. The help repository works best when sustained engagement moves conversation forward. The issue will be closed in 1 month. If you are still experiencing this issue on the latest supported versions of Node.js, please leave a comment. |
Closing after no activity on this issue for 12 months. |
Details
I am trying to use the NodeJS Embedder API in a C++ application. My goal would be to load JS modules that might contain
import
statement. What would be the best way to go about that?So far, I have created a
v8::Module
and I can instantiate it and run it without trouble. However, I have issue importing modules especially default ones such aspath
. I am not sure what would be the best way to resolve module recursively taking into account the internal modules nodejs exposes (path
,http
, etc...)What would be the best way to achieve something like that?
Node.js version
v18.10.0
Example code
Example with custom module execution:
Operating system
MacOS Monterey 12.6, but not that relevant for this particular question
Scope
Embedder API
Module and version
Not applicable.
The text was updated successfully, but these errors were encountered: