Skip to content

Failed to run ffish.js and examples in node.js #868

@xianminx

Description

@xianminx

I want to use a js (with wasm) version of this lib for a web xiangqi project and find two versions of bindings:

  1. port of Fairy-Stockfish to WebAssembly fairy-stockfish.wasm
  2. The javascript binding ffish.js https://github.com/fairy-stockfish/Fairy-Stockfish/tree/master/tests/js

I am new to make wasm work in the browser. It seems the two are of similar functions, and I am a bit confusing which one to choose. I tried the both version, neither one work in the way I expect.

When I try ffish.js, the downloaded npm packages is as the following:

↑7 node_modules/ffish git:(master) ▶ tree
.
├── README.md
├── docker-compose.yml
├── ffish.d.ts
├── ffish.js
├── ffish.wasm
├── index.js

The npm package directory provides index.js file which is a express server file, and when I run node index.js
it shows the error that it cannot parse url for file ffish.wasm which indeed exist.

I Googled a bit and it means node cannot use fetch to access a local file system, even with file:// prefix.
So when the wasm file is served in the browser, this should work fine. I am curious if this node server file index.js (and test.js) works and if yes, how does it work as expected. What should I have to change or update to make it work too?
Thank you.

Ξ node_modules/ffish git:(master) ▶ node index.js 
Test server of ffish.js listening on port 8000.
http://127.0.0.1:8000/
TypeError: Failed to parse URL from /Users/xxx/dev/workspace/ff/fairy-stockfish-nnue-wasm-demo/node_modules/.pnpm/[email protected]/node_modules/ffish/ffish.wasm
TypeError: Failed to parse URL from /Users/xxx/dev/workspace/ff/fairy-stockfish-nnue-wasm-demo/node_modules/.pnpm/[email protected]/node_modules/ffish/ffish.wasm
/Users/xxx/dev/workspace/ff/fairy-stockfish-nnue-wasm-demo/node_modules/.pnpm/[email protected]/node_modules/ffish/ffish.js:1

.....
RuntimeError: abort(TypeError: Failed to parse URL from /Users/xxx/dev/workspace/ff/fairy-stockfish-nnue-wasm-demo/node_modules/.pnpm/[email protected]/node_modules/ffish/ffish.wasm). Build with -s ASSERTIONS=1 for more info.
    at process.abort (ffish.js:1:11719)
    at process.emit (node:events:520:28)
    at process.emit (node:events:532:35)
    at emitUnhandledRejection (node:internal/process/promises:250:13)
    at throwUnhandledRejectionsMode (node:internal/process/promises:385:19)
    at processPromiseRejections (node:internal/process/promises:470:17)
    at process.processTicksAndRejections (node:internal/process/task_queues:96:32) {
  uncaught: true
}

Node.js v22.2.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions