wxt-dev / wxt-dev/wxt

wasm support at background script.

Open
#1,448 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

pending-triage
Dominant language
TypeScript
Stars
10.5k
Forks
564
PR merge metrics
No merged PRs in 30d

Description

Describe the bug

i am trying to use photon(a wasm image pkg by rust) at my extsion. i got this error Module format "iife" does not support top-level await. Use the "es" or "system" output formats rather.
my wxt version 0.19.27
"@silvia-odwyer/photon": "^0.3.2",

i tried so many ways to solve this problem with helping from AI(cursor the editor), but they all failed.

so is there a way i can resovle this problem ?

here is my wxt config

import {defineConfig} from 'wxt';
import react from '@vitejs/plugin-react';
import wasm from "vite-plugin-wasm";
import topLevelAwait from "vite-plugin-top-level-await";

// See https://wxt.dev/api/config.html
export default defineConfig({
    manifest: {
        permissions: ["activeTab", "scripting", "sidePanel", "storage", "tabs",  "contextMenus", "downloads"],
        action: {},
        name: '__MSG_extName__',
        description: '__MSG_extDescription__',
        default_locale: "en",
        content_security_policy: {
            extension_pages: "script-src 'self' 'wasm-unsafe-eval' http://localhost:3000; object-src 'self';",
            sandbox: "script-src 'self' 'unsafe-inline' 'unsafe-eval' http://localhost:3000; sandbox allow-scripts allow-forms allow-popups allow-modals; child-src 'self';"
          },
    },
    vite: () => ({
        plugins: [react(), wasm(), topLevelAwait({
            // The export name of top-level await promise for each chunk module
            promiseExportName: "__tla",
            // The function to generate import names of top-level await promise in each chunk module
            promiseImportName: i => `__tla_${i}`
        })],
    }),
});


Reproduction

imgarc.zip

Steps to reproduce

run npm run dev

System Info
WXT 0.19.27                                                                                                                               15:41:06
✔ Started dev server @ http://localhost:3000                                                                                             15:41:08
ℹ Pre-rendering chrome-mv3 for development with Vite 6.0.8                                                                               15:41:08
x Build failed in 1.03s

 ERROR  Module format "iife" does not support top-level await. Use the "es" or "system" output formats rather.                            15:41:10
file: F:/selfcode/imgarc/node_modules/.pnpm/@silvia-odwyer+photon@0.3.2/node_modules/@silvia-odwyer/photon/photon_rs_bg.wasm

    file: F:/selfcode/imgarc/node_modules/.pnpm/@silvia-odwyer+photon@0.3.2/node_modules/@silvia-odwyer/photon/photon_rs_bg.wasm
    at getRollupError (/F:/selfcode/imgarc/node_modules/.pnpm/rollup@4.34.8/node_modules/rollup/dist/es/shared/parseAst.js:397:41)
    at error (/F:/selfcode/imgarc/node_modules/.pnpm/rollup@4.34.8/node_modules/rollup/dist/es/shared/parseAst.js:393:42)
    at Module.render (/F:/selfcode/imgarc/node_modules/.pnpm/rollup@4.34.8/node_modules/rollup/dist/es/shared/node-entry.js:16916:20)
    at Chunk.renderModules (/F:/selfcode/imgarc/node_modules/.pnpm/rollup@4.34.8/node_modules/rollup/dist/es/shared/node-entry.js:18668:41)
    at Chunk.render (/F:/selfcode/imgarc/node_modules/.pnpm/rollup@4.34.8/node_modules/rollup/dist/es/shared/node-entry.js:18150:111)
    at /F:/selfcode/imgarc/node_modules/.pnpm/rollup@4.34.8/node_modules/rollup/dist/es/shared/node-entry.js:19845:72
    at Array.map (<anonymous>)
    at renderChunks (/F:/selfcode/imgarc/node_modules/.pnpm/rollup@4.34.8/node_modules/rollup/dist/es/shared/node-entry.js:19845:53)
    at Bundle.generate (/F:/selfcode/imgarc/node_modules/.pnpm/rollup@4.34.8/node_modules/rollup/dist/es/shared/node-entry.js:20108:19)
    at /F:/selfcode/imgarc/node_modules/.pnpm/rollup@4.34.8/node_modules/rollup/dist/es/shared/node-entry.js:22805:27
    at catchUnfinishedHookActions (/F:/selfcode/imgarc/node_modules/.pnpm/rollup@4.34.8/node_modules/rollup/dist/es/shared/node-entry.js:22187:16)
    at buildEnvironment (/F:/selfcode/imgarc/node_modules/.pnpm/vite@6.0.8_@types+node@22.13.4_jiti@1.21.7_yaml@2.7.0/node_modules/vite/dist/node/chunks/dep-Beq30MX9.js:50941:16)
    at Object.build (/F:/selfcode/imgarc/node_modules/.pnpm/wxt@0.19.27_@types+node@22.13.4_rollup@4.34.8_yaml@2.7.0/node_modules/wxt/dist/core/builders/vite/index.mjs:268:22)
    at buildEntrypoints (/F:/selfcode/imgarc/node_modules/.pnpm/wxt@0.19.27_@types+node@22.13.4_rollup@4.34.8_yaml@2.7.0/node_modules/wxt/dist/core/utils/building/build-entrypoints.mjs:15:18)
    at rebuild (/F:/selfcode/imgarc/node_modules/.pnpm/wxt@0.19.27_@types+node@22.13.4_rollup@4.34.8_yaml@2.7.0/node_modules/wxt/dist/core/utils/building/rebuild.mjs:15:21)
    at internalBuild (/F:/selfcode/imgarc/node_modules/.pnpm/wxt@0.19.27_@types+node@22.13.4_rollup@4.34.8_yaml@2.7.0/node_modules/wxt/dist/core/utils/building/internal-build.mjs:43:32)
    at buildAndOpenBrowser (/F:/selfcode/imgarc/node_modules/.pnpm/wxt@0.19.27_@types+node@22.13.4_rollup@4.34.8_yaml@2.7.0/node_modules/wxt/dist/core/create-server.mjs:119:28)
    at Object.start (/F:/selfcode/imgarc/node_modules/.pnpm/wxt@0.19.27_@types+node@22.13.4_rollup@4.34.8_yaml@2.7.0/node_modules/wxt/dist/core/create-server.mjs:75:7)
    at /F:/selfcode/imgarc/node_modules/.pnpm/wxt@0.19.27_@types+node@22.13.4_rollup@4.34.8_yaml@2.7.0/node_modules/wxt/dist/cli/commands.mjs:32:5
    at CAC.<anonymous> (/F:/selfcode/imgarc/node_modules/.pnpm/wxt@0.19.27_@types+node@22.13.4_rollup@4.34.8_yaml@2.7.0/node_modules/wxt/dist/cli/cli-utils.mjs:17:22)
    at /F:/selfcode/imgarc/node_modules/.pnpm/wxt@0.19.27_@types+node@22.13.4_rollup@4.34.8_yaml@2.7.0/node_modules/wxt/dist/cli/index.mjs:11:1

✖ Command failed after 4.488 s                                                                                                           15:41:10

 ERROR  Failed to build background                                                                                                        15:41:10

    at buildEntrypoints (/F:/selfcode/imgarc/node_modules/.pnpm/wxt@0.19.27_@types+node@22.13.4_rollup@4.34.8_yaml@2.7.0/node_modules/wxt/dist/core/utils/building/build-entrypoints.mjs:19:13)
    at rebuild (/F:/selfcode/imgarc/node_modules/.pnpm/wxt@0.19.27_@types+node@22.13.4_rollup@4.34.8_yaml@2.7.0/node_modules/wxt/dist/core/utils/building/rebuild.mjs:15:21)
    at internalBuild (/F:/selfcode/imgarc/node_modules/.pnpm/wxt@0.19.27_@types+node@22.13.4_rollup@4.34.8_yaml@2.7.0/node_modules/wxt/dist/core/utils/building/internal-build.mjs:43:32)
    at buildAndOpenBrowser (/F:/selfcode/imgarc/node_modules/.pnpm/wxt@0.19.27_@types+node@22.13.4_rollup@4.34.8_yaml@2.7.0/node_modules/wxt/dist/core/create-server.mjs:119:28)
    at Object.start (/F:/selfcode/imgarc/node_modules/.pnpm/wxt@0.19.27_@types+node@22.13.4_rollup@4.34.8_yaml@2.7.0/node_modules/wxt/dist/core/create-server.mjs:75:7)
    at /F:/selfcode/imgarc/node_modules/.pnpm/wxt@0.19.27_@types+node@22.13.4_rollup@4.34.8_yaml@2.7.0/node_modules/wxt/dist/cli/commands.mjs:32:5
    at CAC.<anonymous> (/F:/selfcode/imgarc/node_modules/.pnpm/wxt@0.19.27_@types+node@22.13.4_rollup@4.34.8_yaml@2.7.0/node_modules/wxt/dist/cli/cli-utils.mjs:17:22)
    at /F:/selfcode/imgarc/node_modules/.pnpm/wxt@0.19.27_@types+node@22.13.4_rollup@4.34.8_yaml@2.7.0/node_modules/wxt/dist/cli/index.mjs:11:1

  [cause]: Module format "iife" does not support top-level await. Use the "es" or "system" output formats rather.
file: F:/selfcode/imgarc/node_modules/.pnpm/@silvia-odwyer+photon@0.3.2/node_modules/@silvia-odwyer/photon/photon_rs_bg.wasm

      file: F:/selfcode/imgarc/node_modules/.pnpm/@silvia-odwyer+photon@0.3.2/node_modules/@silvia-odwyer/photon/photon_rs_bg.wasm
      at getRollupError (/F:/selfcode/imgarc/node_modules/.pnpm/rollup@4.34.8/node_modules/rollup/dist/es/shared/parseAst.js:397:41)
      at error (/F:/selfcode/imgarc/node_modules/.pnpm/rollup@4.34.8/node_modules/rollup/dist/es/shared/parseAst.js:393:42)
      at Module.render (/F:/selfcode/imgarc/node_modules/.pnpm/rollup@4.34.8/node_modules/rollup/dist/es/shared/node-entry.js:16916:20)
      at Chunk.renderModules (/F:/selfcode/imgarc/node_modules/.pnpm/rollup@4.34.8/node_modules/rollup/dist/es/shared/node-entry.js:18668:41)
      at Chunk.render (/F:/selfcode/imgarc/node_modules/.pnpm/rollup@4.34.8/node_modules/rollup/dist/es/shared/node-entry.js:18150:111)
      at /F:/selfcode/imgarc/node_modules/.pnpm/rollup@4.34.8/node_modules/rollup/dist/es/shared/node-entry.js:19845:72
      at Array.map (<anonymous>)
      at renderChunks (/F:/selfcode/imgarc/node_modules/.pnpm/rollup@4.34.8/node_modules/rollup/dist/es/shared/node-entry.js:19845:53)
      at Bundle.generate (/F:/selfcode/imgarc/node_modules/.pnpm/rollup@4.34.8/node_modules/rollup/dist/es/shared/node-entry.js:20108:19)
      at /F:/selfcode/imgarc/node_modules/.pnpm/rollup@4.34.8/node_modules/rollup/dist/es/shared/node-entry.js:22805:27
      at catchUnfinishedHookActions (/F:/selfcode/imgarc/node_modules/.pnpm/rollup@4.34.8/node_modules/rollup/dist/es/shared/node-entry.js:22187:16)
      at buildEnvironment (/F:/selfcode/imgarc/node_modules/.pnpm/vite@6.0.8_@types+node@22.13.4_jiti@1.21.7_yaml@2.7.0/node_modules/vite/dist/node/chunks/dep-Beq30MX9.js:50941:16)
      at Object.build (/F:/selfcode/imgarc/node_modules/.pnpm/wxt@0.19.27_@types+node@22.13.4_rollup@4.34.8_yaml@2.7.0/node_modules/wxt/dist/core/builders/vite/index.mjs:268:22)
      at buildEntrypoints (/F:/selfcode/imgarc/node_modules/.pnpm/wxt@0.19.27_@types+node@22.13.4_rollup@4.34.8_yaml@2.7.0/node_modules/wxt/dist/core/utils/building/build-entrypoints.mjs:15:18)
      at rebuild (/F:/selfcode/imgarc/node_modules/.pnpm/wxt@0.19.27_@types+node@22.13.4_rollup@4.34.8_yaml@2.7.0/node_modules/wxt/dist/core/utils/building/rebuild.mjs:15:21)
      at internalBuild (/F:/selfcode/imgarc/node_modules/.pnpm/wxt@0.19.27_@types+node@22.13.4_rollup@4.34.8_yaml@2.7.0/node_modules/wxt/dist/core/utils/building/internal-build.mjs:43:32)
      at buildAndOpenBrowser (/F:/selfcode/imgarc/node_modules/.pnpm/wxt@0.19.27_@types+node@22.13.4_rollup@4.34.8_yaml@2.7.0/node_modules/wxt/dist/core/create-server.mjs:119:28)
      at Object.start (/F:/selfcode/imgarc/node_modules/.pnpm/wxt@0.19.27_@types+node@22.13.4_rollup@4.34.8_yaml@2.7.0/node_modules/wxt/dist/core/create-server.mjs:75:7)
      at /F:/selfcode/imgarc/node_modules/.pnpm/wxt@0.19.27_@types+node@22.13.4_rollup@4.34.8_yaml@2.7.0/node_modules/wxt/dist/cli/commands.mjs:32:5
      at CAC.<anonymous> (/F:/selfcode/imgarc/node_modules/.pnpm/wxt@0.19.27_@types+node@22.13.4_rollup@4.34.8_yaml@2.7.0/node_modules/wxt/dist/cli/cli-utils.mjs:17:22)
      at /F:/selfcode/imgarc/node_modules/.pnpm/wxt@0.19.27_@types+node@22.13.4_rollup@4.34.8_yaml@2.7.0/node_modules/wxt/dist/cli/index.mjs:11:1

 ELIFECYCLE  Command failed with exit code 1.
Used Package Manager

npm

Validations

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the attached imgarc.zip reproduction and the vite configuration shown in the issue, then run npm run dev to reproduce the background build failure. Trace how the WASM package and top-level-await plugins are processed for the background script. Done means the reproduction builds successfully without the iife/top-level-await error.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, vite, wasm
Domain
build-system, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.