Skip to content

noVNC cannot be bundled due to top-level await in browser.js #1943

@mudge

Description

@mudge

Describe the bug
3677afe introduced a top-level await in lib/util/browser.js which prevents the library from being bundled with esbuild when previously it was fine.

To reproduce
Steps to reproduce the behavior:

  1. In a new directory, run npm install -S @novnc/novnc esbuild
  2. Create an index.js with import RFB from "@novnc/novnc";
  3. Attempt to bundle the file with npx esbuild index.js --bundle
  4. See errors like the following:
    ✘ [ERROR] This require call is not allowed because the imported file "node_modules/@novnc/novnc/lib/util/browser.js" contains a top-level await
    
        node_modules/@novnc/novnc/lib/rfb.js:11:23:
          11 │ var _browser = require("./util/browser.js");
             ╵                        ~~~~~~~~~~~~~~~~~~~
    
      The top-level await in "node_modules/@novnc/novnc/lib/util/browser.js" is here:
    
        node_modules/@novnc/novnc/lib/util/browser.js:179:68:
          179 │ exports.supportsWebCodecsH264Decode = supportsWebCodecsH264Decode = await _checkWebCodecsH264DecodeSupport();
              ╵                                                                     ~~~~~
    

Expected behavior
The file bundles successfully.

Server (please complete the following information):

  • noVNC version: 1.6.0
  • esbuild version: 0.25.1
  • Node version: v20.9.0
  • OS: macOS 15.3.1

Additional context
This happens even when using esbuild's default target of esnext. Is it possible to compile a version of browser.js that does not use a top-level await?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions