wxt icon indicating copy to clipboard operation
wxt copied to clipboard

wasm support at background script.

Open Trojanking123 opened this issue 11 months ago • 2 comments

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/@[email protected]/node_modules/@silvia-odwyer/photon/photon_rs_bg.wasm

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

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

 ELIFECYCLE  Command failed with exit code 1.

Used Package Manager

npm

Validations

Trojanking123 avatar Feb 18 '25 08:02 Trojanking123

Try this https://wxt.dev/api/reference/wxt/interfaces/BackgroundDefinition.html#type

aiktb avatar Feb 18 '25 15:02 aiktb

Cursor tangent

Yeah, cursor ain't gonna help you with WXT unless you give it context. WXT is new enough it's not in most training sets.

WXT hosts some knowledge files containing the whole docs, not sure if you can load them into cursor automatically somehow. ~200k tokens FYI

https://wxt.dev/guide/resources/faq.html#is-there-an-llm-trained-on-wxt-s-docs-that-i-chat-with

aklinker1 avatar Feb 18 '25 23:02 aklinker1