sql.js icon indicating copy to clipboard operation
sql.js copied to clipboard

Unable to bundle due to "fs" (sveltekit + cloudflare workers).

Open hadson172 opened this issue 4 months ago • 0 comments

Sql.js seems like really amazing pice of technology so I would like to use it in one of the projects. The tech stack of project is

  • sveltekit
  • cloudflare workers

Started for the project was taken from here - https://developers.cloudflare.com/pages/framework-guides/deploy-a-svelte-kit-site/#setting-up-a-new-project

I would like to use sqlite inside svelte' loader function (+layout.server.ts) to be more specific. It is the code which runs on the server (cloudflare workers) due to fetch requests to load the data.

My setup looks like this:

import initSqlDb from 'sql.js/dist/sql-wasm.js';
	
const SQL = await initSqlDb();

i've tried also this

import initSqlJs from "sql.js/dist/sql-wasm.js";

const SQL = await initSqlJs({
  locateFile: file => `https://cdnjs.cloudflare.com/ajax/libs/sql.js/1.6.2/${file}`
});

Here is the error I am getting:

Image

As you can see, it is correltly linked to wasm.js version.

When I look inside sql-wasm.js file, I see that there is fs reference:

Image

Is it possible to make this working somehow?

hadson172 avatar Sep 17 '25 13:09 hadson172