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

stockfish is not a function

Open thomasxd24 opened this issue 7 years ago • 9 comments

i have done this:

var stockfish = require("stockfish"); chesses[id] = new Chess(); console.log('Chess game: ', message.author.username + ' vs NeuroChess'); thinking[id] = false; stockfishes[id] = STOCKFISH(); stockfishes[id].postMessage('setoption name Contempt value 30'); stockfishes[id].postMessage('setoption name Skill Level value 20'); stockfishes[id].postMessage('ucinewgame'); stockfishes[id].postMessage('isready');

it shows that

ReferenceError: STOCKFISH is not defined

any solution?

thomasxd24 avatar Oct 28 '17 17:10 thomasxd24

Since your named the variable as stockfish on the first line, then you should call stockfishes[id] = stockfish().

nmrugg avatar Oct 29 '17 11:10 nmrugg

same thing,

TypeError: stockfish is not a function

thomasxd24 avatar Oct 30 '17 07:10 thomasxd24

Maybe this will help.

I just did this:

npm i stockfish

And then created this file and it works:

var id = 0;
var stockfish = require("stockfish");
var stockfishes = [];

stockfishes[id] = stockfish();

stockfishes[id].onmessage = function (message) {
    console.log("received: " + message);
}

stockfishes[id].postMessage('setoption name Contempt value 30');
stockfishes[id].postMessage('setoption name Skill Level value 20');
stockfishes[id].postMessage('ucinewgame');
stockfishes[id].postMessage('isready');

Also checkout https://github.com/nmrugg/stockfish.js/blob/master/load_engine.js.

nmrugg avatar Oct 30 '17 07:10 nmrugg

I met the same issue when using with Vue:

const stockfish = require("stockfish")
this.engine = stockfish();

nganphtgit avatar Aug 02 '19 09:08 nganphtgit

I met the same problem as @nganphtgit when using Vue. Despite trying many variation of the import function the file returns an empty object, {}. Any suggestions ?

honkskillet avatar May 10 '20 06:05 honkskillet

@honkskillet I used the Worker way, let see my demonstration: https://github.com/nganphtgit/chess-bot

nganphtgit avatar May 10 '20 11:05 nganphtgit

@nganphtgit Did you just manually copy stockfish.js in the public folder of your project and then run the following? this.engine = new Worker("stockfish.js");

This didn't work for me.

honkskillet avatar May 10 '20 13:05 honkskillet

@honkskillet I coppied 3 files: *.js, *.wasm and *.asm, 3 files will be placed at public folder, the file stockfish.js will be embed in index.html and I used post/get message with Worker to get data.

nganphtgit avatar May 10 '20 13:05 nganphtgit

@nganphtgit I tried this for React. It doesn't seem to work. I also tried adding those files to the folder containing the file instantiating the worker. Is there a work around?

pranavmodx avatar Jun 14 '20 17:06 pranavmodx