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

Couldn't import ConnectyCube when using vite #118

Open
codersuraz opened this issue Sep 7, 2024 · 2 comments
Open

Couldn't import ConnectyCube when using vite #118

codersuraz opened this issue Sep 7, 2024 · 2 comments

Comments

@codersuraz
Copy link

I have installed the connectycube npm package and tried to import it to my vue app served through vite.

I got this error:

Uncaught (in promise) ReferenceError: global is not defined
    at node_modules/@xmpp/websocket/lib/Socket.js (connectycube.js?v=afa2b33d:2247:22)
    at __require2 (chunk-PR4QN5HX.js?v=afa2b33d:14:50)
    at node_modules/@xmpp/websocket/lib/Connection.js (connectycube.js?v=afa2b33d:2352:18)
    at __require2 (chunk-PR4QN5HX.js?v=afa2b33d:14:50)
    at node_modules/@xmpp/websocket/index.js (connectycube.js?v=afa2b33d:2392:31)
    at __require2 (chunk-PR4QN5HX.js?v=afa2b33d:14:50)
    at node_modules/@xmpp/client/react-native.js (connectycube.js?v=afa2b33d:3364:22)
    at __require2 (chunk-PR4QN5HX.js?v=afa2b33d:14:50)
    at node_modules/connectycube/lib/cubeDependencies.js (connectycube.js?v=afa2b33d:3466:22)
    at __require2 (chunk-PR4QN5HX.js?v=afa2b33d:14:50)

Expected Behavior

We should be able to import the module when using vite.

@DaveLomber
Copy link
Contributor

@codersuraz could you try to add window.global = window before ConnectyCube.init

@DaveLomber
Copy link
Contributor

Another way is by adding this to vite.config.ts:

export default defineConfig({
  plugins: ...
  esbuild: ...

  define: {
    // By default, Vite doesn't include shims for NodeJS/
    // necessary for segment analytics lib to work
    global: {},
  },
})

ref vitejs/vite#5912 (comment)

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

2 participants