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]: v7: "global" module alias breaks package that uses the real "global" package #21242

Closed
Jack-Works opened this issue Feb 24, 2023 · 7 comments · Fixed by #22393
Closed

Comments

@Jack-Works
Copy link

Describe the bug

Storybook crashes with

ModuleNotFoundError: Module not found: Error: Can't resolve 'global/window' in 'xhr'

global is its own package, and is used by a package xhr.

image

storybook v7's default webpack config includes an alias which breaks the build.

To Reproduce

No response

System

Environment Info:

  System:
    OS: Windows 10
  Binaries:
    Node: 19.3.0 - C:\Program Files\nodejs\node.EXE
    npm: 9.2.0 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.22621.1325.0), Chromium (110.0.1587.50)
  npmPackages:
    @storybook/addon-actions: ^7.0.0-beta.53 => 7.0.0-beta.53
    @storybook/addon-essentials: ^7.0.0-beta.53 => 7.0.0-beta.53
    @storybook/addon-links: ^7.0.0-beta.53 => 7.0.0-beta.53
    @storybook/react: ^7.0.0-beta.53 => 7.0.0-beta.53
    @storybook/react-webpack5: ^7.0.0-beta.53 => 7.0.0-beta.53

Additional context

No response

@xylophonehero
Copy link

Temp fix by adding these lines to the webpackFinal function in the storybook main file

  webpackFinal: async (config) => {
    // Removing the global alias as it conflicts with the global npm pkg
    const { global, ...alias } = config.resolve.alias
    config.resolve.alias = alias
    
    // Other config
  }

https://storybook.js.org/docs/react/builders/webpack

@mallio
Copy link

mallio commented Apr 21, 2023

I'm having this same issue within a storybook addon "@storybook/addon-console", which has a require('global/window') that webpack can't resolve. The workaround seems to fix it, but makes me question why storybook is aliasing a package that some of their own addons require to a different package.

@tmeasday
Copy link
Member

tmeasday commented May 2, 2023

@ndelangen ☝️ what's happening here?

@ndelangen
Copy link
Member

👀

@ndelangen
Copy link
Member

Yeah this is just a bug in 7.0, I'll remove the alias!

@shilman
Copy link
Member

shilman commented May 19, 2023

Boo-yah!! I just released https://github.com/storybookjs/storybook/releases/tag/v7.1.0-alpha.20 containing PR #22393 that references this issue. Upgrade today to the @future NPM tag to try it out!

npx sb@next upgrade --tag future

@shilman
Copy link
Member

shilman commented May 22, 2023

Gadzooks!! I just released https://github.com/storybookjs/storybook/releases/tag/v7.0.13 containing PR #22393 that references this issue. Upgrade today to the @latest NPM tag to try it out!

npx sb@latest upgrade

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

Successfully merging a pull request may close this issue.

6 participants