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

Cannot find module '.\node_modules\stockfish\src\stockfish.worker.js'

Open DrMeepso opened this issue 1 year ago • 8 comments

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!

DrMeepso avatar Nov 22 '22 04:11 DrMeepso

You may need to compile the code.

scchess avatar Jan 14 '23 02:01 scchess

You may need to compile the code.

How do I compile the code after installing it with npm i stockfish?

AllLuckBased avatar Jan 16 '23 11:01 AllLuckBased

Have you found a solution? Faced to the same problem

Digitall333 avatar Jan 26 '23 23:01 Digitall333

issuing the same with node@16

import Stockfish from "stockfish";
const engine = Stockfish()();
engine.then(() => console.log('init'), console.error)

arthurchumak avatar Mar 20 '23 10:03 arthurchumak

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

arthurchumak avatar Mar 22 '23 15:03 arthurchumak

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.

atomflunder avatar May 05 '23 20:05 atomflunder

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);

gazeau avatar May 11 '23 17:05 gazeau

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?

GabeK0 avatar May 26 '23 17:05 GabeK0