I want to use default export with synthetic module in V8. I have synthetic_module
, a module which exposes C++ functions to JS, and code like the following:
Local<String> txt = String::NewFromUtf8(isolate, u8R"(
import defaultFoo from './myModule.js';
defaultFoo();
").ToLocalChecked();
...
ScriptCompiler::Source src(txt, origin);
static Local<Module> module
= ScriptCompiler::CompileModule(isolate, &src).ToLocalChecked();
// module->GetStatus() is kUninstantiated here
module->InstantiateModule(context,
[](Local<Context> context,
Local<String> specifier,
Local<Module> referrer) -> MaybeLocal<Module> {
return synthetic_module;
});
// module->GetStatus() is still kUninstantiated
// if synthetic_module does not have default export
Using v8::TryCatch
, I can get a SyntaxError
that synthetic_module
does not have default export. Is there a way to set default export when using synthetic module in V8? Thanks for your answer in advance.