Skip to content

Allow spreading config into defineContentScript #2400

Description

@aaronklinker-st

Describe the bug

When I try to do this:

export default defineContentScript({
  ...SOME_SHARED_CONFIG,

  async main(ctx) {
    // ...
  }
})

I get the following error from wxt prepare:

WXT 0.20.13                                                                                                                                                                                                                                                                        10:05:35 AM
 Generating types...
 Command failed after 1.390 s

 ERROR  Cannot read properties of undefined (reading 'name')                                                                                                                                                                                                                       10:05:37 AM

    at node_modules/.pnpm/wxt@0.20.13_@types+node@25.0.3_jiti@1.21.7_rollup@4.55.1_yaml@2.8.2/node_modules/wxt/dist/core/utils/transform.mjs:23:28
    at Array.filter (<anonymous>)
    at emptyMainFunction (node_modules/.pnpm/wxt@0.20.13_@types+node@25.0.3_jiti@1.21.7_rollup@4.55.1_yaml@2.8.2/node_modules/wxt/dist/core/utils/transform.mjs:22:107)
    at removeMainFunctionCode (node_modules/.pnpm/wxt@0.20.13_@types+node@25.0.3_jiti@1.21.7_rollup@4.55.1_yaml@2.8.2/node_modules/wxt/dist/core/utils/transform.mjs:4:3)
    at TransformPluginContext.handler (node_modules/.pnpm/wxt@0.20.13_@types+node@25.0.3_jiti@1.21.7_rollup@4.55.1_yaml@2.8.2/node_modules/wxt/dist/core/builders/vite/plugins/removeEntrypointMainFunction.mjs:12:27)
    at EnvironmentPluginContainer.transform (node_modules/.pnpm/vite@7.3.1_@types+node@25.0.3_jiti@1.21.7_yaml@2.8.2/node_modules/vite/dist/node/chunks/config.js:28797:51)
    at loadAndTransform (node_modules/.pnpm/vite@7.3.1_@types+node@25.0.3_jiti@1.21.7_yaml@2.8.2/node_modules/vite/dist/node/chunks/config.js:22670:26)

I can fix this by adding an optional chain operator here:

  // node_modules/wxt/dist/core/utils/transform.mjs
        mod.exports.default.$ast.arguments[0].properties = mod.exports.default.$ast.arguments[0].properties.filter(
-         (prop) => prop.key.name !== "main"
+         (prop) => prop.key?.name !== "main"
        );

Reproduction

See code above

Steps to reproduce

wxt prepare

System Info

System:
    OS: macOS 26.4.1
    CPU: (11) arm64 Apple M3 Pro
    Memory: 363.55 MB / 36.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 24.15.0 - /Users/aaron/.asdf/installs/nodejs/24.15.0/bin/node
    npm: 11.12.1 - /Users/aaron/.asdf/plugins/nodejs/shims/npm
    pnpm: 9.11.0 - /Users/aaron/.asdf/installs/nodejs/24.15.0/bin/pnpm
    bun: 1.3.13 - /Users/aaron/.bunv/bin/bun
    Deno: 2.7.14 - /opt/homebrew/bin/deno
  Browsers:
    Chrome Canary: 150.0.7863.0
    Safari: 26.4
  npmPackages:
    vite: ^7.3.1 => 7.3.1
    wxt: ^0.20.13 => 0.20.13

Used Package Manager

pnpm

Validations

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No fields configured for Bug.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions