Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
DrMeepso opened this issue Nov 22, 2022 · 8 comments
Open

Comments

@DrMeepso
Copy link

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!
@scchess
Copy link
Contributor

scchess commented Jan 14, 2023

You may need to compile the code.

@AllLuckBased
Copy link

You may need to compile the code.

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

@Digitall333
Copy link

Have you found a solution? Faced to the same problem

@arthurchumak
Copy link

issuing the same with node@16

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

@arthurchumak
Copy link

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

@atomflunder
Copy link

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.

@gazeau
Copy link

gazeau commented May 11, 2023

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

@GabeK0
Copy link

GabeK0 commented May 26, 2023

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants