See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import.meta
The import.meta object is a meta-property exposing context-specific meta data to a JavaScript module. It contains information about the module, like the module's URL.
The motivation can be read on TC39 stage 3 page: https://github.com/tc39/proposal-import-meta/#importmeta
This is already a living standard on a vast majority of engines and is useful to implement script loaders, that require relative paths. When using modules .mjs or the content-type application/javascript+module the information should be already available to graaljs, so it should be a matter of exposing it... (the devil is on the details... ;-)
Hi Paulo,
we do support import.meta, but we might not yet have all the right properties (e.g. URL that you mentioned).
As it is a stage 3 proposal, we only have it in ECMAScript 2020 mode, i.e. you need to set --js.ecmascript-version=2020.
Best,
Christian
@wirthi just be clear, my issue is not related to the node binary, I'm looking into using it from the embedded script side.
Hi Paulo,
Also for embeddings, we currently support ES2019 by default. Newer features might be available if you set option("js.ecmascript-version", "2020") on the Context.
Best,
Christian
Yes I was aware of it. I commented because the issue got labeled "nodejs" .
Ah, got it, that is incorrect of course.
I assume the issue is resolved when you set the flag as specified above. Please comment & reopen if this is not the case, thanks!
@wirthi on 19.0.0, the meta object is present but the url isn't present,
final Context context = Context.newBuilder("js")
.builder.option("js.ecmascript-version", "2020")
.build();
context.eval(
Source
.newBuilder("js", "import { f } from './mjs/meta.mjs';\n f();", "myscript.mjs")
.mimeType(""application/javascript+module")
.buildLiteral());
And the mjs/meta.mjs file looks like:
console.log(typeof import.meta.url);
export function f () {
console.log(import.meta.url);
}
And it prints:
undefined
Where I'd expect:
./mjs/meta.mjs
the meta object is present but the url isn't present,
FYI: We set url property of import.meta by now, see https://github.com/graalvm/graaljs/commit/65f28d2f20afeec545f19075a89db5fd7c0ccfe0.
Most helpful comment
FYI: We set
urlproperty ofimport.metaby now, see https://github.com/graalvm/graaljs/commit/65f28d2f20afeec545f19075a89db5fd7c0ccfe0.