hipstersmoothie / storybook-dark-mode

A storybook addon that lets your users toggle between dark and light mode.
MIT License
429 stars 56 forks source link

Storybook v7 (beta 36) Cannot read properties of undefined (reading 'document') when import from 'global' #214

Closed dartess closed 1 year ago

dartess commented 1 year ago

Hey!

I'm trying out the new storybook beta and I've run into a problem:

runtime.mjs:4 Error reading preview.js
runtime.mjs:4 TypeError: Cannot read properties of undefined (reading 'document')
    at ./node_modules/storybook-dark-mode/dist/esm/Tool.js (Tool.js:45:1)
    at options.factory (react refresh:6:1)
    at __webpack_require__ (bootstrap:24:1)
    at fn (hot module replacement:47:1)
    at ./node_modules/storybook-dark-mode/dist/esm/index.js (Sun.js:30:1)
    at options.factory (react refresh:6:1)
    at __webpack_require__ (bootstrap:24:1)
    at fn (hot module replacement:47:1)
    at ./.storybook/preview.tsx (DocContainer.tsx:7:1)
    at options.factory (react refresh:6:1)

Also after that I get a warning:

[HMR] bundle 'preview' has 7 warnings
client.js:197 ./node_modules/@storybook/addon-docs/dist/chunk-R4NKYYJA.mjs 1:37-44
Critical dependency: require function is used in a way in which dependencies cannot be statically extracted
./node_modules/@storybook/addon-docs/dist/chunk-R4NKYYJA.mjs 1:166-173
Critical dependency: require function is used in a way in which dependencies cannot be statically extracted
./node_modules/storybook-dark-mode/dist/esm/Tool.js 42:12-18
export 'default' (imported as 'global') was not found in 'global' (possible exports: global)
./node_modules/storybook-dark-mode/dist/esm/Tool.js 42:20-26
export 'default' (imported as 'global') was not found in 'global' (possible exports: global)
./node_modules/storybook-dark-mode/dist/esm/Tool.js 42:38-44
export 'default' (imported as 'global') was not found in 'global' (possible exports: global)
./node_modules/storybook-dark-mode/dist/esm/Tool.js 42:54-60
export 'default' (imported as 'global') was not found in 'global' (possible exports: global)
./node_modules/storybook-dark-mode/dist/esm/Tool.js 44:11-17
export 'default' (imported as 'global') was not found in 'global' (possible exports: global)

I tried to log global in the console, it is displayed twice, the first time is correct, the second is undefined.

I'm not sure if this is a plugin issue since the storybook is still in beta, but thought I'd report the issue here. Let me know if this is not a problem on your side.

Untel commented 1 year ago

Facing the same issue here, with @storybook/nextjs addon.

hipstersmoothie commented 1 year ago

If anyone wants to help me upgrade to v7 I'd appreciate it. Willing to merge whatever is found

SpookyJelly commented 1 year ago

I am using Sb v7 beta 38. but got no problem. Have you tried this version?? Maybe issue you faced fixed in this ver

dartess commented 1 year ago

@SpookyJelly the same in @44 =\

Namielusi commented 1 year ago

Replacing the global package with the @storybook/global seems to fix the issue. I've created a pull request with that change.

hipstersmoothie commented 1 year ago

:rocket: Issue was released in v2.0.6 :rocket:

dartess commented 1 year ago

@Namielusi thanks!