storybook-dark-mode
storybook-dark-mode copied to clipboard
Cannot read property 'matchMedia' of undefined -- window is undefined
After upgrading storybook/react to 6.5.13 (from 6.4.22) I suddenly have problems with storybook-dark-mode not wanting to load because window
is undefined. See the full callstack below. I was on [email protected], upgraded to 1.1.2. Same error in both versions.
I'm using webpack5, [email protected]
Any ideas what could be going wrong here?
Failed to load preset: {"type":"presets","name":"/app/.yarn/__virtual__/storybook-dark-mode-virtual-6715300bd7/0/cache/storybook-dark-mode-npm-1.1.2-ecc4605688-8.zip/node_modules/storybook-dark-mode/dist/index.js"} on level 1
ERR! TypeError: Cannot read property 'matchMedia' of undefined
ERR! at Object.<anonymous> (/app/.yarn/__virtual__/storybook-dark-mode-virtual-6715300bd7/0/cache/storybook-dark-mode-npm-1.1.2-ecc4605688-8.zip/node_modules/storybook-dark-mode/dist/Tool.js:64:30)
ERR! at Module._compile (internal/modules/cjs/loader.js:1085:14)
ERR! at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
ERR! at Module.load (internal/modules/cjs/loader.js:950:32)
ERR! at Function.external_module_.Module._load (/app/.pnp.cjs:48904:14)
ERR! at Module.require (internal/modules/cjs/loader.js:974:19)
ERR! at require (internal/modules/cjs/helpers.js:101:18)
ERR! at Object.<anonymous> (/app/.yarn/__virtual__/storybook-dark-mode-virtual-6715300bd7/0/cache/storybook-dark-mode-npm-1.1.2-ecc4605688-8.zip/node_modules/storybook-dark-mode/dist/index.js:28:14)
ERR! at Module._compile (internal/modules/cjs/loader.js:1085:14)
ERR! at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
ERR! at Module.load (internal/modules/cjs/loader.js:950:32)
ERR! at Function.external_module_.Module._load (/app/.pnp.cjs:48904:14)
ERR! at Module.require (internal/modules/cjs/loader.js:974:19)
ERR! at require (internal/modules/cjs/helpers.js:101:18)
ERR! at interopRequireDefault (/app/.yarn/__virtual__/@storybook-core-common-virtual-5880bee6e4/0/cache/@storybook-core-common-npm-6.5.13-49981d30f1-8.zip/node_modules/@storybook/core-common/dist/cjs/presets.js:178:16)
ERR! at getContent (/app/.yarn/__virtual__/@storybook-core-common-virtual-5880bee6e4/0/cache/@storybook-core-common-npm-6.5.13-49981d30f1-8.zip/node_modules/@storybook/core-common/dist/cjs/presets.js:194:10)
ERR! TypeError: Cannot read property 'matchMedia' of undefined
ERR! at Object.<anonymous> (/app/.yarn/__virtual__/storybook-dark-mode-virtual-6715300bd7/0/cache/storybook-dark-mode-npm-1.1.2-ecc4605688-8.zip/node_modules/storybook-dark-mode/dist/Tool.js:64:30)
ERR! at Module._compile (internal/modules/cjs/loader.js:1085:14)
ERR! at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
ERR! at Module.load (internal/modules/cjs/loader.js:950:32)
ERR! at Function.external_module_.Module._load (/app/.pnp.cjs:48904:14)
ERR! at Module.require (internal/modules/cjs/loader.js:974:19)
ERR! at require (internal/modules/cjs/helpers.js:101:18)
ERR! at Object.<anonymous> (/app/.yarn/__virtual__/storybook-dark-mode-virtual-6715300bd7/0/cache/storybook-dark-mode-npm-1.1.2-ecc4605688-8.zip/node_modules/storybook-dark-mode/dist/index.js:28:14)
ERR! at Module._compile (internal/modules/cjs/loader.js:1085:14)
ERR! at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
ERR! at Module.load (internal/modules/cjs/loader.js:950:32)
ERR! at Function.external_module_.Module._load (/app/.pnp.cjs:48904:14)
ERR! at Module.require (internal/modules/cjs/loader.js:974:19)
ERR! at require (internal/modules/cjs/helpers.js:101:18)
ERR! at interopRequireDefault (/app/.yarn/__virtual__/@storybook-core-common-virtual-5880bee6e4/0/cache/@storybook-core-common-npm-6.5.13-49981d30f1-8.zip/node_modules/@storybook/core-common/dist/cjs/presets.js:178:16)
ERR! at getContent (/app/.yarn/__virtual__/@storybook-core-common-virtual-5880bee6e4/0/cache/@storybook-core-common-npm-6.5.13-49981d30f1-8.zip/node_modules/@storybook/core-common/dist/cjs/presets.js:194:10)