You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I believe recent versions of V8 have native support for ESM modules (https://v8.dev/features/modules). I don't think this is bridged to V8Js via the setModuleLoader though (which perhaps just does something like provide a require function declaration to the JS runtime).
NodeJS uses the ".mjs" file extension, the package.json"type" field, or the --input-type flag. How this can be implemented? V8Js::executeModule()?
And if after that I call V8Js::executeScript()? It's possible? Every module has their unique context. They will share the context of the scripts that are executed with V8JS::executeScript() like browsers do?
Just throwing some thoughts about how this can be implemented! 😄
It feels like the only way to implement it natively would be to essentially treat the initial executed code as a module itself, so that import would work similar to require Perhaps wrapping the executed code with an internal entry script of sorts.
I managed to get something working a year or two back, albeit using babel to transpile code before executing. Just not in a native way.
I will look on this to use here for now, I really liked. Today I have typescript compiler embedded, like deno do. 😅
So, why not babel? 😆
But to run es6 modules on v8 it's a little different than "normal" scripts, maybe some of the commonjs implementation can be reused but with de v8's module calls.
FYI I've also / mostly moved work from v8js to php-deno (https://github.com/joehoyle/php-deno) which has support for Es6 modules natively (and also have the TypeScript compiler via swc embedded)
I implemented a basic compileModuleString, executeModule and executeModuleString.
Lacks imports resolution. It just return the referrer module itself for testing purposes.
If someone is interested, my code is here: https://github.com/chrisbckr/v8js/tree/php8-es6_modules
Activity
chrisbckr commentedon Feb 20, 2023
NodeJS uses the
".mjs"file extension, thepackage.json"type"field, or the--input-typeflag. How this can be implemented? V8Js::executeModule()?And if after that I call V8Js::executeScript()? It's possible? Every module has their unique context. They will share the context of the scripts that are executed with V8JS::executeScript() like browsers do?
Just throwing some thoughts about how this can be implemented! 😄
redbullmarky commentedon Feb 20, 2023
It feels like the only way to implement it natively would be to essentially treat the initial executed code as a module itself, so that
importwould work similar torequirePerhaps wrapping the executed code with an internal entry script of sorts.I managed to get something working a year or two back, albeit using babel to transpile code before executing. Just not in a native way.
redbullmarky commentedon Feb 20, 2023
@chrisbckr This was part of the original test I played around with:
chrisbckr commentedon Feb 21, 2023
I will look on this to use here for now, I really liked. Today I have typescript compiler embedded, like deno do. 😅
So, why not babel? 😆
But to run es6 modules on v8 it's a little different than "normal" scripts, maybe some of the commonjs implementation can be reused but with de v8's module calls.
joehoyle commentedon Feb 21, 2023
FYI I've also / mostly moved work from v8js to php-deno (https://github.com/joehoyle/php-deno) which has support for Es6 modules natively (and also have the TypeScript compiler via swc embedded)
chrisbckr commentedon Feb 22, 2023
I implemented a basic compileModuleString, executeModule and executeModuleString.
Lacks imports resolution. It just return the referrer module itself for testing purposes.
If someone is interested, my code is here:
https://github.com/chrisbckr/v8js/tree/php8-es6_modules