Skip to content

bug: Error using jeep-sqlite in NX monorepo (Angular and Ionic): WebAssembly.instantiate() fails when loading sql-wasm.wasm #634

@vladt-e

Description

@vladt-e

Plugin version:

"@capacitor-community/sqlite": "^6.0.2"

Platform(s):

Web (Angular app inside NX monorepo)

Current behavior:

Using sqlite plugin with jeep-sqlite in an Angular app inside an NX monorepo results in the following WebAssembly errors when loading in the browser:

Image

Expected behavior:

The SQLite WebAssembly module should initialize without errors, allowing database access in the browser as expected.

Steps to reproduce:

  1. Create a new Ionic app with Angular inside an NX monorepo
  2. Install capacitor-community/sqlite plugin and sql-wasm.wasm file from "node_modules/sql.js/dist/sql-wasm.wasm" to "apps//src/assets"
  3. Initialize the component using jeepSqlite(window)
  4. Append the element to the DOM
  5. Load the app in the browser
  6. Check the console for WebAssembly error

Related code:

Here is how I load the plugin for browser into the main.ts file. This configuration is loaded before the app initializes

if (Capacitor.getPlatform() === 'web') {
  jeepSqlite(window);

  window.addEventListener('DOMContentLoaded', async () => {
    const jeepEl = document.createElement('jeep-sqlite');
    jeepEl.autoSave = true;
    // Also tried: jeepEl.setAttribute('wasm-path', 'assets/sql-wasm.wasm');
    document.body.appendChild(jeepEl);
    await customElements.whenDefined('jeep-sqlite');
  });
}

By the other side, the app is initialized with the following methods and the error occurs after executing the database initialization

 async initPlugin(): Promise<void> {
    this.dbConnection = new SQLiteConnection(CapacitorSQLite);

    if (Capacitor.getPlatform() === 'web') {
      await CapacitorSQLite.initWebStore();
    } else {
      const isDevEncrypt = await this.isDeviceEncryption();

      if (isDevEncrypt) {
        await this.setEncryptionPassphrase('<passphrase>');
      }
    }

    await this.initDatabase();
  }

async initDatabase() {
    await CapacitorSQLite.addUpgradeStatement({
      database: this.dbName,
      upgrade: this.versionUpgrades,
    });

    this.db = await this.openDatabase(this.dbName, this.loadToVersion, false);

    if (Capacitor.getPlatform() === 'web') {
      await this.dbConnection.saveToStore(this.dbName);
    }
  }

Other information:

Capacitor doctor:

💊   Capacitor Doctor  💊 

Latest Dependencies:

  @capacitor/cli: 7.2.0
  @capacitor/core: 7.2.0
  @capacitor/android: 7.2.0
  @capacitor/ios: 7.2.0

Installed Dependencies:

  @capacitor/cli: 6.2.0
  @capacitor/ios: 6.1.2
  @capacitor/core: 6.2.0
  @capacitor/android: 6.1.2

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions