sql.js
                                
                                 sql.js copied to clipboard
                                
                                    sql.js copied to clipboard
                            
                            
                            
                        Does not work in node as advertised
With given package.json:
{
	"type": "module",
	"packageManager": "[email protected]",
	"dependencies": { "sql.js": "1.7.0" }
}
Here's the result of node -e 'require("sql.js")()':
(node:31583) ExperimentalWarning: The Fetch API is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
node:internal/deps/undici/undici:4813
            throw new TypeError("Failed to parse URL from " + input, { cause: err });
                  ^
TypeError: Failed to parse URL from /home/[redacted]/node_modules/.pnpm/[email protected]/node_modules/sql.js/dist/sql-wasm.wasm
    at new Request (node:internal/deps/undici/undici:4813:19)
    at Agent.fetch2 (node:internal/deps/undici/undici:5505:29)
    ... 4 lines matching cause stack trace ...
    at /home/[redacted]/node_modules/.pnpm/[email protected]/node_modules/sql.js/dist/sql-wasm.js:158:505
    at new Promise (<anonymous>)
    at initSqlJs (/home/[redacted]/node_modules/.pnpm/[email protected]/node_modules/sql.js/dist/sql-wasm.js:22:24)
    at [eval]:1:18 {
  [cause]: TypeError [ERR_INVALID_URL]: Invalid URL
      at new NodeError (node:internal/errors:377:5)
      at URL.onParseError (node:internal/url:563:9)
      at new URL (node:internal/url:643:5)
      at new Request (node:internal/deps/undici/undici:4811:25)
      at Agent.fetch2 (node:internal/deps/undici/undici:5505:29)
      at Object.fetch (node:internal/deps/undici/undici:6332:20)
      at fetch (node:internal/bootstrap/pre_execution:196:25)
      at /home/[redacted]/node_modules/.pnpm/[email protected]/node_modules/sql.js/dist/sql-wasm.js:158:271
      at /home/[redacted]/node_modules/.pnpm/[email protected]/node_modules/sql.js/dist/sql-wasm.js:158:492
      at /home/[redacted]/node_modules/.pnpm/[email protected]/node_modules/sql.js/dist/sql-wasm.js:158:505 {
    input: '/home/[redacted]/node_modules/.pnpm/[email protected]/node_modules/sql.js/dist/sql-wasm.wasm',
    code: 'ERR_INVALID_URL'
  }
}
Node.js v18.3.0
I'm using [email protected] with ES modules and had to explicitly set a path to the wasm binary:
  const wasmBinary = await readFile(new URL("../node_modules/sql.js/dist/sql-wasm.wasm", import.meta.url));
  const SQLJS = await initSql({
    wasmBinary,
  });
Hope that helps!
@jmandzik I have failed to use the option you mentioned above. https://github.com/sql-js/sql.js/issues/522
The problem on my side is that the readFile does not allow to take more than one arguments. Which readFile module that you once import?
@sigridjineth
The problem on my side is that the
readFiledoes not allow to take more than one arguments.
Read again carefully, there's two parameters in new URL(..., ...), not await readFile(...)
- The URL constructor can have two parameters: one for relative path, and one for base path.
- Actually, Node.js' readFilecan have two parameters: 2nd parameter for file options.
I am facing the same issue on an existing project where the only change I did was in node version to 20.
Seems like Node 18 issue now. https://github.com/netlify/cli/issues/4610.