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
Using import.meta.url inside a class method results in a SyntaxError: Cannot use 'import.meta' outside a module. This error occurs during the module's import, even without instantiating the class or invoking the method.
The source code is valid & functional when used in a <script type="module">.
constcompartment=newCompartment({__options__: true,globals: {
console,},importHook: async(specifier: string): Promise<any>=>{if(specifier=="test"){constmodule={source: newModuleSource(`console.log("Can use import.meta normally", import.meta.url); export class Test { constructor() { console.log("This throws error", import.meta.url); } }`),
specifier,
compartment,};returnmodule;}},importMetaHook: (_moduleSpecifier: string,meta: any)=>{
meta.url='https://example.com';},});compartment.import("test");
Steps to Reproduce
Create a Compartment with importHook and importMetaHook.
Use importHook to return a ModuleSource containing code with a class method that accesses import.meta.url.
Observe the error.
Expected Behavior
The code snippet with import.meta.url inside a class method should execute without errors, as it does with standard <script type="module">.
VM6833:5 Uncaught (in promise) SyntaxError: Cannot use 'import.meta' outside a module
at Object.eval (eval at makeEvaluate (make-evaluate.js:92:27), <anonymous>:12:36)
at safeEvaluate (make-safe-evaluator.js:78:14)
at compartmentEvaluate (compartment-evaluate.js:90:10)
at makeModuleInstance (module-instance.js:445:18)
at instantiate (module-link.js:124:22)
at link (module-link.js:53:10)
at compartmentImportNow (compartment.js:58:37)
at compartment.js:121:27
The text was updated successfully, but these errors were encountered:
Thank you for reporting. This reveals an incompleteness in the @endo/module-source Babel transform, which evidently is not visiting every ImportMeta node in the AST.
Describe the Bug
Using
import.meta.url
inside a class method results in aSyntaxError: Cannot use 'import.meta' outside a module
. This error occurs during the module's import, even without instantiating the class or invoking the method.The source code is valid & functional when used in a
<script type="module">
.Steps to Reproduce
Compartment
withimportHook
andimportMetaHook
.importHook
to return aModuleSource
containing code with a class method that accessesimport.meta.url
.Expected Behavior
The code snippet with
import.meta.url
inside a class method should execute without errors, as it does with standard<script type="module">
.Platform Environment
1.71.114 Chromium: 130.0.6723.58 (Official Build) (64-bit)
Additional Context
Error Message:
The text was updated successfully, but these errors were encountered: