stockfish.js
stockfish.js copied to clipboard
Cannot find module '.\node_modules\stockfish\src\stockfish.worker.js'
i keep getting this error when i try and run my code with NodeJS
pthread sent an error! undefined:undefined: Cannot find module 'C:\Users\user\Desktop\ChessWeb\node_modules\stockfish\src\stockfish.worker.js'
This is my code
const stockfish = require("stockfish");
const engine = stockfish();
let myEngine;
async function StartEngine() {
await engine().then((sf) => {
myEngine = sf;
myEngine.onmessage = function (message) {
console.log("received: " + message);
}
})
myEngine.postMessage("uci");
myEngine.postMessage("ucinewgame");
let fenString = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"
myEngine.postMessage(`position ${fenString}`);
myEngine.postMessage("go depth 20");
}
StartEngine()
Thanks
- Meepso!
You may need to compile the code.
You may need to compile the code.
How do I compile the code after installing it with npm i stockfish
?
Have you found a solution? Faced to the same problem
issuing the same with node@16
import Stockfish from "stockfish";
const engine = Stockfish()();
engine.then(() => console.log('init'), console.error)
I've solved it with using example below, and cloning repo into my project, without installing npm module https://github.com/nmrugg/stockfish.js/blob/v15.0.0/example/node_abstraction.js
I am having the same error while trying to compile Stockfish 15 running the build.js
file.
When compiling Stockfish 11 this problem does not occur and it compiles just fine.
I downloaded the .zip
file manually in both cases, the required compiler is installed and I am following the steps outlined in the README file.
Any help would be appreciated, as the documentation is frankly abysmal.
I've solved it with using example below, and cloning repo into my project, without installing npm module https://github.com/nmrugg/stockfish.js/blob/v15.0.0/example/node_abstraction.js
I also used @arthurchumak proposal as a temporary workaround and I got it working.
I created a directory on my project with a subfolder called "engine" that contains:
- load_engine.js (you can get it on the examples)
- stockfish.js (copy pasted the src/stockfish.js, not very elegant but at least it works)
Then on my code I called it with
const loadEngine = require('./engine/load_engine.js');
const engine = loadEngine(require('path').join(__dirname, 'engine/stockfish.js'));
// example of sending the commands
engine.send(
'go infinite',
function onDone(data: string) {
console.log('DONE:', data);
engine.quit();
},
function onStream(data: string) {
console.log('STREAMING:', data);
}
);
setTimeout(function () {
engine.send('stop');
resolve({ from: 'x', to: 'x' });
}, 1000);
When I try @arthurchumak or @gazeau's solution, I get these errors:
STREAMING: /opt/homebrew/Cellar/node/20.0.0/bin/node: bad option: --experimental-wasm-simd
STREAMING: /opt/homebrew/Cellar/node/20.0.0/bin/node: bad option: --experimental-wasm-threads
Perhaps I need to be on a specific version of Node, any ideas?