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: importing daily.co in React with esBuild gives "Uncaught ReferenceError: global is not defined" #163

Open
iamwilhelm opened this issue May 17, 2021 · 4 comments
Labels
bug Something isn't working

Comments

@iamwilhelm
Copy link

Expected behavior

While using esBuild, I expect to add:

import DailyIframe from "@daily-co/daily-js"

without a problem

Describe the bug (unexpected behavior)

esBuild succeeds in building the react app, but when loading in the browser, yields "Uncaught ReferenceError: global is not defined" in the console.

Steps to reproduce

The solution is to define global=window in esBuild's build configs.

https://esbuild.github.io/api/#define

In a build script:

esbuild.build({
  ...other build configs
  define: {
    global: "window"
  }
})

in the command line, add --define:global=window

Action to take

Mention this in the https://docs.daily.co/reference#using-the-dailyco-front-end-library

under the section for "Bundling with webpack and other tools"

@kachar
Copy link

kachar commented Oct 4, 2021

I got the same problem when using Vite

In order to resolve it I had to add the following to vite.config.ts:

export default defineConfig({
  define: {
    global: 'window',
  },
})

More info can be found at https://vitejs.dev/config/#define

@jmordica
Copy link

I got the same problem when using Vite

In order to resolve it I had to add the following to vite.config.ts:

export default defineConfig({
  define: {
    global: 'window',
  },
})

More info can be found at https://vitejs.dev/config/#define

This resolved the issue for me as well using Vite

@rememberlenny
Copy link

Also hit this.

@aamiriqubal
Copy link

Please use 'esbuild-plugin-polyfill-node' plugin.
https://npm.io/package/esbuild-plugin-polyfill-node

plugins: [
    polyfillNode({
    }),
]

This solved the problem for me.

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

5 participants