Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Cannot read properties of undefined (reading 'navigator') on node with globals #29314

Open
unional opened this issue Oct 9, 2024 · 2 comments

Comments

@unional
Copy link
Contributor

unional commented Oct 9, 2024

Describe the bug

I have a project containing both server and client code.
So I want to run tests also in node.

When I run vitest, I get Cannot read properties of undefined (reading 'navigator') error:

TypeError: Cannot read properties of undefined (reading 'navigator')
 ❯ resetClipboardStubOnView node_modules/.pnpm/@[email protected][email protected]/node_modules/@storybook/test/dist/index.mjs:178:7052
 ❯ node_modules/.pnpm/@[email protected][email protected]/node_modules/@storybook/test/dist/index.mjs:178:8238

This occurs when I set test.globals: true in vite.config.ts.

Reproduction link

https://github.com/cyberuni/sb-test-nav

Reproduction steps

run pnpm test

System

npx storybook@latest info

Storybook Environment Info:

System:
OS: macOS 14.7
CPU: (10) arm64 Apple M1 Pro
Shell: 5.9 - /bin/zsh
Binaries:
Node: 22.9.0 - ~/.local/state/fnm_multishells/74613_1728508612022/bin/node
Yarn: 1.22.21 - ~/.nvm/versions/node/v20.12.2/bin/yarn
npm: 10.8.3 - ~/.local/state/fnm_multishells/74613_1728508612022/bin/npm <----- active
pnpm: 8.15.6 - ~/.nvm/versions/node/v20.12.2/bin/pnpm
Browsers:
Chrome: 129.0.6668.90
Safari: 18.0
npmPackages:
@storybook/addon-essentials: ^8.3.5 => 8.3.5
@storybook/addon-interactions: ^8.3.5 => 8.3.5
@storybook/addon-links: ^8.3.5 => 8.3.5
@storybook/addon-onboarding: ^8.3.5 => 8.3.5
@storybook/blocks: ^8.3.5 => 8.3.5
@storybook/react: ^8.3.5 => 8.3.5
@storybook/react-vite: ^8.3.5 => 8.3.5
@storybook/test: ^8.3.5 => 8.3.5
eslint-plugin-storybook: ^0.9.0 => 0.9.0
storybook: ^8.3.5 => 8.3.5

Additional context

The @storybook/test is probably doing some work at load time which is not ideal.

It should avoid that or at least check for window?...

@Siddhant-Kashyap
Copy link

want to work on this @unional ,please assign it to me

@shilman
Copy link
Member

shilman commented Oct 13, 2024

@Siddhant-Kashyap No need to assign. If you make a PR we'd be happy to review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants