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

webpack browser build broken due to usage of "global" #493

Open
vecernik opened this issue Mar 6, 2018 · 10 comments
Open

webpack browser build broken due to usage of "global" #493

vecernik opened this issue Mar 6, 2018 · 10 comments

Comments

@vecernik
Copy link

vecernik commented Mar 6, 2018

I really love this project, I use it for browser and node client and server projects.
With current version (1.2.1) building faye with webpack works but fails in runtime (browsers) due to missing "global".
I noticed a few sources (in /protocol/client, /util and /mixins) use "global" as a keyword, specially while calling onbeforeunload() and setTimeout(), which could be fine for node (but why?), but can't work for browsers.
Is there a solution for projects with no direct access to webpack config, i.e. angular/cli?
Perhaps to use more ambivalent checks for window|global, or better, to separate code for browser and node?

@jcoglan
Copy link
Collaborator

jcoglan commented Jun 10, 2019

Hi @vecernik, sorry for my slow response. Are you still having this problem with version 1.2.4? The way our own webpack build is set up, it includes a module called webpack/buildin/global.js into the build, which binds global to the window object in compiled code. We didn't do anything special to request that, I believe webpack does it by default.

If you're not getting this file in your build, it's probably due to how you have webpack configured.

@jcoglan
Copy link
Collaborator

jcoglan commented Jun 10, 2019

If you're having issues with how webpack compiles Faye from source, you can also use the pre-bundled minified file from the faye package -- the file you want is named faye-browser-min.js. We include this browser-ready version alongside the full source code.

@vecernik
Copy link
Author

with faye-1.2.4, I still need self['global'] = self manual polyfill for a browser in Typescript (angular8) project for a use in import { Client } from 'faye'.

@jcoglan
Copy link
Collaborator

jcoglan commented Jun 11, 2019

If you run the following command in the Faye repo, do you see the global.js module included?

./node_modules/.bin/webpack --display-modules

@mirono
Copy link

mirono commented Jun 13, 2019

I have a similar issue with production build. In my case I use it in Vue application. The development build is working correctly, but the production build is not getting any messages. The console prints that subscribe was ok but messages never arrive. Same code in development (using the same faye node server) works ok.
It has something to do with the packing to the dist folder.

@jcoglan
Copy link
Collaborator

jcoglan commented Jun 14, 2019

In order to make progress with this I need someone to find out whether webpack is including webpack/buildin/global.js in their build, and if not, why?

@mirono
Copy link

mirono commented Jun 15, 2019

I'll be happy to assist, just tell me what/how to do.
BTW: In my case, when I removed client.disable('websocket') it also worked in production. With this line it only worked in dev.

@jcoglan
Copy link
Collaborator

jcoglan commented Feb 14, 2020

@mirono Sorry for my delayed response. If you're still having a problem with this, clone this repo and run:

$ npm install
$ ./node_modules/.bin/webpack --display-modules

The output should include this line:

[./node_modules/webpack/buildin/global.js] (webpack)/buildin/global.js 472 bytes {build/client/faye-browser} {spec/browser_bundle} [built]

If the issue is resolve, please close it :)

@brendon
Copy link

brendon commented Jul 27, 2022

This is also an issue in Vite (at least in dev mode - esbuild). Haven't checked what it builds out like in production mode.

Without Webpack helping (I'm trying to transition from Webpack to Vite as I write this), would a polyfill like self['global'] = self be required?

@brendon
Copy link

brendon commented Jul 27, 2022

Just to follow up, I am only using Faye in one particular part of my Rails app that has its own layout, so I just added <script>window.global = window</script> into the header and all is well. I wonder if a something like that could be added to faye_browser?

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

No branches or pull requests

4 participants