Ui plugin throws "server crashed, window is not defined"

Author: PiTiLeZarDCreated Aug 3, 2024Updated Aug 18, 2024

What's wrong?

It might be my misunderstanding of cosmos plugins, if it is, feel free to close this.

I'm coding a plugin that will use @axe-core/react on a click of a button. I've used react-cosmos-plugin-open-fixture as a template. The plugin axe throws a window is not defined exception.

Steps to reproduce

  1. clone this: https://github.com/PiTiLeZarD/react-cosmos-plugin-axe
  2. npm install && npm run build
  3. ln -s this folder in the node_modules of the react cosmos
  4. add "react-cosmos-plugin-axe" in the list of plugins in cosmos.config.json
  5. cosmos broken

Useful info

cosmos 6.1.1 the server displays:

[Cosmos] Using cosmos config found at cosmos.config.json
[Cosmos] Server crashed...

  (╯°□°)╯︵ ┻━┻

ReferenceError: window is not defined
    at Object.<anonymous> (/Users/me/workspaces/react-cosmos-plugin-axe/node_modules/@axe-core/react/dist/index.js:100:13)
    at Module._compile (node:internal/modules/cjs/loader:1364:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1422:10)
    at Module.load (node:internal/modules/cjs/loader:1203:32)
    at Function.Module._load (node:internal/modules/cjs/loader:1019:12)
    at Module.require (node:internal/modules/cjs/loader:1231:19)
    at require (node:internal/modules/helpers:177:18)
    at Object.<anonymous> (/Users/me/workspaces/react-cosmos-plugin-axe/dist/ui.js:5:27)
    at Module._compile (node:internal/modules/cjs/loader:1364:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1422:10)

Additional context

I'm using parcel.

Source: react-cosmos/react-cosmos