sql-js / sql-js/sql.js

Cannot set property 'exports' of undefined

Open
#406 16 comments 8 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

I'm trying to get Sql.js working with TypeORM inside Electron as part of the renderer but I'm running into an error I don't know how to handle. I'm getting the error: TypeError: Cannot set property 'exports' of undefined. I'm not sure if this is a configuration issue on my end or if there's some sort of bug. It seems like the error happens somewhere in initSqlJs before it gets to locating the wasm binary.

My setup is as follows:

WebPack Config

module.exports = {
    entry: {main: './main.ts'},
    output: {/*Removed for brevity*/},
    target: 'electron-renderer',
    module: {/*Removed for brevity*/},
    plugins: [
        /*Other plugins removed for brevity*/
        new Webpack.NormalModuleReplacementPlugin(/typeorm$/, function (result) {
            result.request = result.request.replace(/typeorm/, "typeorm/browser");
        }),
        new Webpack.ProvidePlugin({
            'window.SQL': 'sql.js/dist/sql-wasm.js'
        }),
        new CopyPlguin({
            patterns: [
                {from: './node_modules/sql.js/dist/sql-wasm.wasm'}
            ]
        })
    ]
}

Main Code

const initSqlJs = require('sql.js');

const SQL = await initSqlJs({
	locateFile: (file: any) => {
		console.log(file); //This line is never printed
		return `https://cdnjs.cloudflare.com/ajax/libs/sql.js/1.1.0/dist/${file}`}
});

var db = new SQL.Database();

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 Webpack configuration and the require('sql.js') call, then inspect where initSqlJs fails before locateFile runs. Reproduce the error in the Electron renderer and compare the bundled module/export behavior; done means determining whether the configuration or sql.js causes the error and documenting a verified resolution.

Written by the indexing model from the issue text.

Assessment

Tech stack
electron, javascript, sqlite, wasm, webpack
Domain
build-system, database, desktop
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.