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

Does not work in node as advertised

Open xnuk opened this issue 3 years ago • 4 comments

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

xnuk avatar Jun 13 '22 05:06 xnuk

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 avatar Jul 09 '22 20:07 jmandzik

@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 avatar Jul 21 '22 18:07 sigridjineth

@sigridjineth

The problem on my side is that the readFile does not allow to take more than one arguments.

Read again carefully, there's two parameters in new URL(..., ...), not await readFile(...)

xnuk avatar Jul 22 '22 10:07 xnuk

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.

Anutrix avatar Nov 14 '23 09:11 Anutrix