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] Failed to resolve import "global" with yarn PNP #371

Closed
1 task
Arnagos opened this issue May 7, 2022 · 6 comments
Closed
1 task

[Bug] Failed to resolve import "global" with yarn PNP #371

Arnagos opened this issue May 7, 2022 · 6 comments
Labels
bug Something isn't working

Comments

@Arnagos
Copy link

Arnagos commented May 7, 2022

What version of vite are you using?

2.9.8

System info and storybook versions

System:
OS: Windows 10 10.0.22000
CPU: (24) x64 AMD Ryzen 9 3900X 12-Core Processor
Binaries:
Node: 16.13.1 - C:\Program Files\nodejs\node.EXE
Yarn: 3.2.0 - ~\AppData\Roaming\npm\yarn.CMD
npm: 8.6.0 - C:\Program Files\nodejs\npm.CMD
Browsers:
Edge: Spartan (44.22000.120.0), Chromium (101.0.1210.32)

Describe the Bug

When using storybook and this build with Yarn P'n'P 'global' cannot be found.

Stack trace:
[vite] Internal server error: Failed to resolve import "global" from "..\..\..\..\virtual:\@storybook\builder-vite\setup-addons.js". Does the file exist? Plugin: vite:import-analysis File: /virtual:/@storybook/builder-vite/setup-addons.js 1 | import global from 'global'; | ^ 2 | import createPostMessageChannel from '@storybook/channel-postmessage'; 3 | import createWebSocketChannel from '@storybook/channel-websocket';

Link to Minimal Reproducible Example

Repro

Participation

  • I am willing to submit a pull request for this issue.
@Arnagos Arnagos added the bug Something isn't working label May 7, 2022
@IanVS
Copy link
Member

IanVS commented May 7, 2022

Hi, without a reproduction it's hard to say exactly what is happening. But vite does not polyfill node global, so you'll need to either find out which of your dependencies is using global, or polyfill it yourself. One easy way is to create a .storybook/preview-head.html with this content:

<script>
  window.global = window;
</script>

@Arnagos
Copy link
Author

Arnagos commented May 7, 2022

According to the stack-trace its the '/virtual:/@storybook/builder-vite/setup-addons.js' file that is importing 'global'.
Is that file not part of builder-vite? builder-vite/virtual-file-names.ts contains the reference to it.

Polyfilling it myself, by adding the HTML file with the script, sadly didn't work.

/Edit: builder-vite/codegen-set-addon-channel.ts contains the code.

@Arnagos
Copy link
Author

Arnagos commented May 7, 2022

Note: Everything works fine when using the node-modules nodeLinker. It breaks only when using yarn P'n'P.

@IanVS
Copy link
Member

IanVS commented May 8, 2022

Thanks, if you can provide a minimal reproduction, we can do our best to look into it.

@IanVS IanVS changed the title [Bug] Failed to resolve import "global" [Bug] Failed to resolve import "global" with yarn PNP May 8, 2022
@Arnagos
Copy link
Author

Arnagos commented May 8, 2022

Repro: https://github.com/Arnagos/import-global-repro

@IanVS
Copy link
Member

IanVS commented May 20, 2022

This is fixed by #383. Can you please try version 0.1.34? You may hit other problems, though, as detailed in #141

@IanVS IanVS closed this as completed May 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants