sql-js / sql-js/sql.js

Error when installed from NPM and used with a React App

Open
#282 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
13.7k
Forks
1.1k
PR merge metrics
No merged PRs in 30d

Description

Installing the library from NPM and running it breaks with:

Uncaught (in promise) Error: CompileError: WebAssembly.compile(): expected magic word 00 61 73 6d, found 3c 21 44 4f @+0
    at Object.Module.onAbort (sql-wasm.js:34)
    at B (sql-wasm.js:3614)
    at sql-wasm.js:1024

Here's the minimal code that consistently produces the error above:

import initSqlJs from 'sql.js';

initSqlJs().then(function(SQL){

  // Create a database
  var db = new SQL.Database();
});

And here's a CodeSandbox that demonstrates the problem.

Using the code from the CDN works fine but it exposes a global window.SQL which is harder to mock during testing (among other things) so I'd prefer using the NPM library.

Do you have any pointers on what this magic number business is?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the npm-built sql-wasm.js referenced in the stack trace and compare its loading behavior with the working CDN version. Reproduce the minimal initSqlJs example in the linked CodeSandbox or a React app; done means the npm package loads valid WebAssembly and creates a SQL.Database without the compile error.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, wasm
Domain
database, web-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.