In Chromium extensions under Manifest Version 3, the project throws an error:
This is because in service workers, window is not defined, so isBrowser is false, but process is also not defined by default.
This could not be fixed by webpack's DefinePlugin because of the optional chaining; the optionally-chained expression actually gets transpiled to something quite different in the built package - typeof process?.env?.TXWRAPPER_METADATA_CACHE_MAX !== 'undefined' becomes typeof ((_a = process === null || process === void 0 ? void 0 : process.env) === null || _a === void 0 ? void 0 : _a.TXWRAPPER_METADATA_CACHE_MAX) !== 'undefined', which DefinePlugin can't parse.
Currently in Talisman as we transition to MV3 we're dealing with this by monkey patching a process global variable into the service worker, however we'd like to avoid this if possible.
In Chromium extensions under Manifest Version 3, the project throws an error:
This is because in service workers,
window
is not defined, soisBrowser
is false, butprocess
is also not defined by default.This could not be fixed by webpack's
DefinePlugin
because of the optional chaining; the optionally-chained expression actually gets transpiled to something quite different in the built package -typeof process?.env?.TXWRAPPER_METADATA_CACHE_MAX !== 'undefined'
becomestypeof ((_a = process === null || process === void 0 ? void 0 : process.env) === null || _a === void 0 ? void 0 : _a.TXWRAPPER_METADATA_CACHE_MAX) !== 'undefined'
, whichDefinePlugin
can't parse.Currently in Talisman as we transition to MV3 we're dealing with this by monkey patching a
process
global variable into the service worker, however we'd like to avoid this if possible.