-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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 is not defined
#2618
Comments
Hello @volkanunsal. Please provide a online reproduction by codesandbox or a minimal GitHub repository. Issues labeled by |
I'm also encountering this issue. It happens when trying to use the first I recognize these as globals/builtins, but:
does not seem to actually do anything. |
I'm getting the same error |
Vite doesn't include shims for Node variables like Webpack 4 does (in Version 5, shims also needs to be added by the user). Check other issues like #728, you can use rollup-plugin-node-globals like a previous comment (but it hasn't been updated for a while). Maybe this is also an option https://github.com/ionic-team/rollup-plugin-node-polyfills. Another option is to use modern libraries that do not depend on node globals (or ask for updates in your current dependencies). Let's close this issue because it is better to try to fix this by discussing it with the maintainers of each library. You can also start a Discussion about a particular library or join Vite Land to chat with others about possible solutions. |
As a work around for anyone who stumbles upon this issue, if the library you are attempting to use is also provided via a CDN, you can use that CDN instead. Since the CDN version is built for the browser it shouldn't have any node-only libraries so you will be able to use it in Vite. To do so first you will want to use the Vite CDN Plugin from Evan(currently unpublished) . After installing that plugin you can then use it to import your library via the CDN. The plugin will automatically download it and use it in place of the one installed via node_modules. Here are two example repositories of this in action |
I'm confused. Why is this issue closed? @felixakiragreen already mentioned that using the plugins mentioned above did not to solve the problem. I tried this method as well, and also tried using |
@volkanunsal Providing node shims is not a planned addition to Vite and since Webpack 5 is also removing I don't imagine it will ever be. If the libraries you are using are provided via a CDN you can use the workaround I posted above. |
I don’t think you understand the problem.
…On Mon, Mar 22, 2021 at 11:55 PM wheat ***@***.***> wrote:
@volkanunsal <https://github.com/volkanunsal> Providing node shims is not
a planned addition to Vite and since Webpack 5 is also removing I don't
imagine it will ever be. If the libraries you are using are provided via a
CDN you can use the workaround I posted above.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#2618 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AABFAMGQEWSHQNQYLFDGT2TTFAGLPANCNFSM4ZQ23SQQ>
.
|
@volkanunsal if you would like to discuss this further, would you open a Discussion or join Vite Land to chat with others about possible solutions. Thanks! |
No
…On Tue, Mar 23, 2021 at 5:09 AM Matias Capeletto ***@***.***> wrote:
@volkanunsal <https://github.com/volkanunsal> if you would like to
discuss this further, would you open a Discussion
<https://github.com/vitejs/vite/discussions> or join Vite Land
<https://chat.vitejs.dev/> to chat with others about possible solutions.
Thanks!
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#2618 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AABFAMF6DRPG424AOMNLJUTTFBLEPANCNFSM4ZQ23SQQ>
.
|
@volkanunsal well we can't really help you if you don't want to have any discussion on it 😅 |
For reference, if you only need to shim <script>window.global = window;</script> to your index.html |
Describe the bug
I'm getting
global is not defined
error.Reproduction
The header of the file has this comment block.
It seems to be coming from a module that includes Node.js modules, and the browser equivalent has been included, and there is a
global
keyword in there, which vitejs cannot seem to handle.System Info
[email protected]
The text was updated successfully, but these errors were encountered: