histoire-dev / histoire-dev/histoire
Window is not defined when trying to generate the build
- Dominant language
- TypeScript
- Stars
- 3.6k
- Forks
- 212
- PR merge metrics
- No merged PRs in 30d
Description
### Describe the bug
I'm trying to generate the build and I'm getting error, probably the problem is with the `window is not defined`, any way to fix this?
```
Error while collecting story /Users/andrewwei/dev/epsilon/src/Shared/CopyClipboard/CopyClipboard.story.svelte:
ReferenceError: window is not defined
at getWindow (/Users/andrewwei/dev/epsilon/node_modules/@floating-ui/dom/dist/floating-ui.dom.esm.js:18:109)
at isElement (/Users/andrewwei/dev/epsilon/node_modules/@floating-ui/dom/dist/floating-ui.dom.esm.js:46:27)
at /Users/andrewwei/dev/epsilon/node_modules/@floating-ui/dom/dist/floating-ui.dom.esm.js:485:59
at Array.filter ()
at getClippingElementAncestors (/Users/andrewwei/dev/epsilon/node_modules/@floating-ui/dom/dist/floating-ui.dom.esm.js:485:46)
at Object.getClippingRect (/Users/andrewwei/dev/epsilon/node_modules/@floating-ui/dom/dist/floating-ui.dom.esm.js:517:71)
at detectOverflow (/Users/andrewwei/dev/epsilon/node_modules/@floating-ui/core/dist/floating-ui.core.esm.js:245:62)
at async fn (/Users/andrewwei/dev/epsilon/node_modules/@floating-ui/core/dist/floating-ui.core.esm.js:563:24)
at async Module.computePosition (/Users/andrewwei/dev/epsilon/node_modules/@floating-ui/core/dist/floating-ui.core.esm.js:126:9)
node:internal/process/promises:279
triggerUncaughtException(err, true /* fromPromise */);
^
ReferenceError [Error]: window is not defined
at getWindow (/Users/andrewwei/dev/epsilon/node_modules/@floating-ui/dom/dist/floating-ui.dom.esm.js:18:109)
at isElement (/Users/andrewwei/dev/epsilon/node_modules/@floating-ui/dom/dist/floating-ui.dom.esm.js:46:27)
at /Users/andrewwei/dev/epsilon/node_modules/@floating-ui/dom/dist/floating-ui.dom.esm.js:485:59
at Array.filter ()
at getClippingElementAncestors (/Users/andrewwei/dev/epsilon/node_modules/@floating-ui/dom/dist/floating-ui.dom.esm.js:485:46)
at Object.getClippingRect (/Users/andrewwei/dev/epsilon/node_modules/@floating-ui/dom/dist/floating-ui.dom.esm.js:517:71)
at detectOverflow (/Users/andrewwei/dev/epsilon/node_modules/@floating-ui/core/dist/floating-ui.core.esm.js:245:62)
at async fn (/Users/andrewwei/dev/epsilon/node_modules/@floating-ui/core/dist/floating-ui.core.esm.js:563:24)
at async Module.computePosition (/Users/andrewwei/dev/epsilon/node_modules/@floating-ui/core/dist/floating-ui.core.esm.js:126:9)
```
### Reproduction
This happens when I tried to generate the build for production.
### System Info
```shell
System:
OS: macOS 13.0
CPU: (8) arm64 Apple M1 Pro
Memory: 87.70 MB / 16.00 GB
Shell: 5.8.1 - /bin/zsh
Binaries:
Node: 16.18.1 - ~/.nvm/versions/node/v16.18.1/bin/node
npm: 8.19.2 - ~/.nvm/versions/node/v16.18.1/bin/npm
Browsers:
Brave Browser: 111.1.49.120
Chrome: 111.0.5563.64
Firefox: 110.0
Safari: 16.1
npmPackages:
vite: ^4.0.0 => 4.1.4
```
### Used Package Manager
npm
### Validations
- [X] Follow our [Code of Conduct](https://github.com/histoire-dev/histoire/blob/main/CODE_OF_CONDUCT.md)
- [X] Read the [Contributing Guidelines](https://github.com/histoire-dev/histoire/blob/main/CONTRIBUTING.md).
- [X] Read the [docs](https://histoire.dev/guide/).
- [X] Check that there isn't [already an issue](https://github.com/histoire-dev/histoire/issues) that reports the same bug to avoid creating a duplicate.
- [X] Check that this is a concrete bug. For Q&A open a [GitHub Discussion](https://github.com/histoire-dev/histoire/discussions).
- [X] The provided reproduction is a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) of the bug.
Contributor guide
Research direction
Start by reproducing the production build while collecting CopyClipboard.story.svelte, then inspect the stack trace through @floating-ui/dom and @floating-ui/core. Trace why the story invokes window during build collection; done means the production build completes without the ReferenceError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript, vite
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100