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

global not defined in webpack project #39

Open
Michriko opened this issue Sep 14, 2021 · 1 comment · May be fixed by #40
Open

global not defined in webpack project #39

Michriko opened this issue Sep 14, 2021 · 1 comment · May be fixed by #40

Comments

@Michriko
Copy link

Background:
In a webpack project depending directly or indirectly via other npm packages on immediate, you need to shim the global variable as webpack does not use the browserified scripts in the dist directory.
In some cases, shiming is not possible (e.g. WebWorker that are created by the AngularCLI).
This causes e.g. the webworker to crash as global is not known.

Proposal:
Do not expect global to be defined.
Define the global variable in index.js and use same logic as in browserify for setting the global object.
Then provide the global Object to all functions relying on global

Michriko pushed a commit to Michriko/immediate that referenced this issue Sep 17, 2021
fixes calvinmetcalf#39

for usage in webpack environments when there is no chance for polyfills, the actual implementation causes crashes, as global is not defined.
the browserified version in the dist directory is not usable for webpack and especially for treeshaking. To fix this, global is not referenced anymore as global variable, it is passed to every function requiring it and the "global polyfill" is prepended to the index.js
@Oisota
Copy link

Oisota commented Jun 11, 2022

Any updates on this? I'm having the same issue building a project with Vite.

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

Successfully merging a pull request may close this issue.

2 participants