wxt icon indicating copy to clipboard operation
wxt copied to clipboard

Build errors when use storage

Open Blon168 opened this issue 8 months ago • 2 comments

Describe the bug

  1. Init project
  2. Change test_wxt\entrypoints\background.ts
Image
  1. run build command:
Image
  1. review background.js
Image

I'm not sure if this can be regarded as a bug. OCD kicking in.

environment: dependencies:

  • vue 3.5.30

devDependencies:

  • @wxt-dev/module-vue 1.0.3
  • typescript 5.9.3
  • vue-tsc 3.2.6
  • wxt 0.20.20

Reproduction

test_wxt.zip

Steps to reproduce

  1. pnpm install
  2. pnpm build

System Info

System:
    OS: Windows 11 10.0.26200
    CPU: (16) x64 Intel(R) Core(TM) Ultra 7 255H
    Memory: 12.64 GB / 31.43 GB
  Binaries:
    Node: 22.19.0 - D:\Program Files\nodejs\node.EXE
    npm: 10.9.3 - D:\Program Files\nodejs\npm.CMD
    pnpm: 10.32.0 - C:\Users\27266\AppData\Local\pnpm\pnpm.CMD
  Browsers:
    Chrome: 145.0.7632.160
    Edge: Chromium (133.0.3065.92)`

Used Package Manager

pnpm

Validations

Blon168 avatar Mar 19 '26 15:03 Blon168

So two things to address:

  1. The bundled output:

    • This is a multi-line string used as the error message. How it appears in your bundled file is correct and perfectly valid JS.

    • It looks a little weird since everything else is bundled onto one line, but it's more efficient to bundle new lines as real characters instead of the escaped \n. Here's a demo showing how esbuilt (which WXT uses) bundles your extension code:

      // test.js
      console.log('line1');
      console.log('This is\nmultiline');
      console.log('line3');
      
      $ pnpm dlx esbuild test.js --minify
      "use strict";console.log("line1"),console.log(`This is
      multi-line`),console.log("line3");
      
    • As you can see, the string with a \n is converted to using backticks and a real newline character in the esbuild minified output. This is because \n is two characters and a real newline is one character - since esbuilt is minifying it goes with the real newline to minimize the file size.

  2. Error thrown at runtime:

    • Your reproduction doesn't work when running pnpm dev because of this error: You must add the 'storage' permission to your manifest to use 'wxt/storage'

      Image
    • This is because you didn't add the storage permission, just like the error message says. The below change fixes your runtime error:

      import { defineConfig } from "wxt";
      
        export default defineConfig({
          modules: ["@wxt-dev/module-vue"],
      +   manifest: {
      +     permissions: ["storage"],
      +   },
        });
      

      See the docs: https://wxt.dev/storage.html#storage-permission

After you add the storage permission, everything works correctly.

aklinker1 avatar Mar 19 '26 16:03 aklinker1

Thank you. I've added the storage permission, but I still get this error message. Sorry, it actually works when it runs. I guess it's just my OCD acting up.

Blon168 avatar Mar 24 '26 06:03 Blon168