Skip to content

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

Closed
@isaachinman

Description

@isaachinman

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions