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

Module "crypto" has been externalized for browser compatibility #423

Open
isaachinman opened this issue Nov 28, 2024 · 0 comments
Open

Module "crypto" has been externalized for browser compatibility #423

isaachinman opened this issue Nov 28, 2024 · 0 comments

Comments

@isaachinman
Copy link

Hello, I am setting up @powersync/web in a Vite application. I have followed the setup instructions closely.

Here is my vite.config.ts:

import pandaPostcss from '@pandacss/dev/postcss'
import { TanStackRouterVite } from '@tanstack/router-plugin/vite'
import react from '@vitejs/plugin-react'
import { Plugin } from 'postcss'
import { defineConfig } from 'vite'
import topLevelAwait from 'vite-plugin-top-level-await'
import wasm from 'vite-plugin-wasm'

export default defineConfig({
  css: {
    postcss: {
      plugins: [
        pandaPostcss() as Plugin,
      ],
    },
  },
  optimizeDeps: {
    exclude: ['@journeyapps/wa-sqlite', '@powersync/web'],
    include: ['@powersync/web > js-logger'],
  },
  plugins: [
    TanStackRouterVite({
      quoteStyle: 'single',
      semicolons: false,
    }),
    react(),
    wasm(),
    topLevelAwait(),
  ],
  resolve: {
    alias: {
      '@my-app': '/src',
    },
  },
  worker: {
    format: 'es',
    plugins: () => [
      wasm(),
      topLevelAwait(),
    ],
  },
})

I see this output on every vite build:

[plugin:vite:resolve] [plugin vite:resolve] Module "crypto" has been externalized for browser compatibility, imported by "/my-app/node_modules/bson/lib/bson.mjs". See https://vite.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.

I am on @powersync/web v1.12.0. The docs say:

Note: As of @powersync/web@1.4.0, polyfills are bundled in the SDK and are no longer required.

However, this error seems to be related to an unpolyfilled crypto call in bson.

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

1 participant