whereby / sdk

MIT License
10 stars 2 forks source link

browser-sdk v3 makes Vite build fails #324

Closed fleonard closed 1 month ago

fleonard commented 1 month ago

I'm trying to using your browser sdk version v3.3.4. We use Vite to build our app and after a bit of struggle to get Buffer working locally I managed to have your web component integration loading and working fine. Isse now is that when I try to build our app with Vite I'm getting the following error

x Build failed in 20.81s
error during build:
../node_modules/@whereby.com/media/dist/index.mjs (10:7): "default" is not exported by "../node_modules/uuid-validate/index.js", imported by "../node_modules/@whereby.com/media/dist/index.mjs".
file: /opt/actions-runner/_work/monorepo/monorepo/node_modules/@whereby.com/media/dist/index.mjs:10:7

 8: import { Address6 } from 'ip-address';
 9: import checkIp from 'check-ip';
10: import validate from 'uuid-validate';
           ^
11: import { io } from 'socket.io-client';

Am I missing something on my side? It's the first time that this happen to me and I'm using Vite for quite a long time so wanted to double check if it was a me issue or it was something on your side.

This is currently my vite config

const viteConfig: UserConfig = {
  define: {
    ...all our env variables,
    "process.env": {},
  },
  resolve: {
    alias: {
      src: path.resolve(__dirname, "./src"),
      buffer: "buffer/",
    },
  },
  plugins: [
    react(),
    relay,
    svgrPlugin(),
    inject({
      Buffer: ["buffer", "Buffer"],
    }),
    TanStackRouterVite(routeConfig),

    isProduction ? null : bundleStats(),
  ],
  server: {
    port: 3000,
    strictPort: true,
    host: true,
  },
  build: {
    sourcemap: true,
    rollupOptions: {
      output: {
        assetFileNames: "assets/[name].[hash][extname]",
        chunkFileNames: "assets/[name].[hash].js",
        entryFileNames: "assets/[name].[hash].js",
        manualChunks: (id) => {
          if (id.includes("/@formatjs")) {
            return "i18n"
          }
          if (id.includes("/glow/assets")) {
            return "glow"
          }
        },
      },
    },
  },
}

export default defineConfig(viteConfig)

Any help would be appreciated 🙏🏻

fleonard commented 1 month ago

closing this. managed to sort this out changing the plugins used to build and provided Buffer in a different way