Web Workers: "_<name> not defined"
Author: aklinker1Created Aug 29, 2024Updated Sep 14, 2026
Labelscontribution welcome
Describe the bug
In the web-worker-setup example, the worker runs just fine, but at the end, it throws and error:
Uncaught ReferenceError: _content is not defined
at worker.ts:1:32
at worker.ts:1:32This is because WXT is adding a return value to all IIFE files. Here's the base64 encoded worker file:
KGZ1bmN0aW9uKCkgewogICJ1c2Ugc3RyaWN0IjsKICBjb25zb2xlLmxvZygiSGVsbG8gZnJvbSB3b3JrZXIiKTsKICBfY29udGVudDsKfSkoKTsKX2NvbnRlbnQ7Ci8vIyBzb3VyY2VNYXBwaW5nVVJMPWRhdGE6YXBwbGljYXRpb24vanNvbjtjaGFyc2V0PXV0Zi04O2Jhc2U2NCxleUoyWlhKemFXOXVJam96TENKbWFXeGxJam9pZDI5eWEyVnlMVU5SZDBOQ05uQndMbXB6SWl3aWMyOTFjbU5sY3lJNld5SXVMaTlsYm5SeWVYQnZhVzUwY3k5amIyNTBaVzUwTDNkdmNtdGxjaTUwY3lKZExDSnpiM1Z5WTJWelEyOXVkR1Z1ZENJNld5SmpiMjV6YjJ4bExteHZaeWhjSWtobGJHeHZJR1p5YjIwZ2QyOXlhMlZ5WENJcE8xeHVJbDBzSW01aGJXVnpJanBiWFN3aWJXRndjR2x1WjNNaU9pSTdPMEZCUVVFc1ZVRkJVU3hKUVVGSkxHMUNRVUZ0UWpzN095SjkKHere it is decoded.
(function() {
"use strict";
console.log("Hello from worker");
_content;
})();
_content;
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoid29ya2VyLUNRd0NCNnBwLmpzIiwic291cmNlcyI6WyIuLi9lbnRyeXBvaW50cy9jb250ZW50L3dvcmtlci50cyJdLCJzb3VyY2VzQ29udGVudCI6WyJjb25zb2xlLmxvZyhcIkhlbGxvIGZyb20gd29ya2VyXCIpO1xuIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBQUEsVUFBUSxJQUFJLG1CQUFtQjs7OyJ9
In this case, because the worker is loaded from entrypoints/content.ts, the error is "_content not defined".
Reproduction
https://github.com/wxt-dev/examples/tree/main/examples/web-worker-setup
Steps to reproduce
pnpm dev
System Info
System:
OS: macOS 14.2.1
CPU: (8) arm64 Apple M1 Pro
Memory: 2.57 GB / 16.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 18.20.3 - ~/.asdf/installs/nodejs/18.20.3/bin/node
npm: 10.7.0 - ~/.asdf/plugins/nodejs/shims/npm
pnpm: 8.15.8 - ~/.asdf/installs/nodejs/18.20.3/bin/pnpm
bun: 1.1.22 - ~/.bun/bin/bun
Browsers:
Chrome: 128.0.6613.85
Safari: 17.2.1
npmPackages:
wxt: ^0.18.6 => 0.18.15Used Package Manager
pnpm
Validations
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Source: wxt-dev/wxt