Skip to content

Load script as module #353

Open
Open
@JasonBarnabe

Description

@JasonBarnabe

mini_racer 0.18.1
libv8-node 23.6.1.0
Ruby 3.4.2

JavaScript modules are different than classic scripts in a few ways. As an example, in a module, you can do a top-level await, but in a classic script, you can't.

> require 'mini_racer'
=> false
> context = MiniRacer::Context.new(timeout: 500, max_memory: 20_000_000)
=> #<MiniRacer::Context:0x00007f11ecd95148>
> context.eval('await Promise.resolve(console.log("🎉"));')
:3:in 'MiniRacer::Context#eval': Uncaught SyntaxError: await is only valid in async functions and the top level bodies of modules at <eval>:1:0 (MiniRacer::ParseError)
        from :3:in '<main>'

I would like to be able to load code as a module with mini_racer.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions