Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[testing] Detect dependencies to add to the ssr.noExternal option #475

Open
aklinker1 opened this issue Feb 21, 2024 · 0 comments
Open

[testing] Detect dependencies to add to the ssr.noExternal option #475

aklinker1 opened this issue Feb 21, 2024 · 0 comments
Labels
Milestone

Comments

@aklinker1
Copy link
Collaborator

aklinker1 commented Feb 21, 2024

Feature Request

If you use a module that imports/depends on webextension-polyfill, you must add the module to Vite's ssr.noExternal option in your vitest.config.ts file:

// vitest.config.ts
import { defineConfig } from 'vitest/config';
import { WxtVitest } from 'wxt/testing';

export default defineConfig({
  plugins: [WxtVitest()],
  ssr: {
    noExternal: ["@webext-core/storage"],
  },
})

In this case, @webext-core/storage depends on webextension-polyfill, so it needs to be added.

If you don't add it to ssr, you'll get errors like this:

Caution

Error: This script should only be loaded in a browser extension

In theory, WXT should be able to perform an analysis of your dependencies, and add all of them automatically to ssr, like it does with WXT itself:

ssr: {
// Inline all WXT modules
noExternal: ['wxt'],
},

You can see a list of dependencies that depend on webextension-polyfill using pnpm list webextension-polyfill:

$ pnpm ls webextension-polyfill --depth Infinity
...
wxt 0.16.11-alpha1
└── webextension-polyfill 0.10.0

Not sure if there's an equivalent for other package managers.

Is your feature request related to a bug?

"N/A"

What are the alternatives?

Add better documentation around this requirement, it can be confusing to deal with. Will do both.

Additional context

wxt-dev/wxt-examples#15

@aklinker1 aklinker1 changed the title [testing] Automatically detect dependencies that depend on webextension-polyfill and add them to the ssr option [testing] Automatically detect dependencies to add to the ssr.noExternal option Feb 21, 2024
@aklinker1 aklinker1 changed the title [testing] Automatically detect dependencies to add to the ssr.noExternal option [testing] Detect dependencies to add to the ssr.noExternal option Feb 21, 2024
@aklinker1 aklinker1 added this to the v1.1 milestone Mar 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant