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

Syntax error in stockfish.js

Open joopdegroot opened this issue 3 years ago • 15 comments

I downloaded stockfish.js-master.zip (the November 11, 2021 version, with Stockfish 14.1) When I run example/index.html in my localhost ( http://localhost/stockfish.js-master/example/index.html ) the console reports (after the message "UCI: isready") this error: stockfish.js:1 Uncaught SyntaxError: Unexpected token '.' The engine won't make a move. It just displays "Engine: loading..." Screenshot attached. screenshot

joopdegroot avatar Dec 14 '21 07:12 joopdegroot

Hmmm.... @joopdegroot, what browser are you using?

nmrugg avatar Dec 17 '21 18:12 nmrugg

I use Chrome (But in FireFox it's the same problem.) I work in Windows.

joopdegroot avatar Dec 17 '21 18:12 joopdegroot

The error message does not make sense as there is no . token in stockfish.js line 1. I'm guessing it's an issue with the symlink. Are you on Windows? It may not be able to handle it. You may need to delete the stockfish.js and stockfish.wasm files from example/ and replace them with the real files from src/.

nmrugg avatar Dec 17 '21 19:12 nmrugg

That makes a difference, but I get new errors:

[Deprecation] SharedArrayBuffer will require cross-origin isolation as of M92, around July 2021. See https://developer.chrome.com/blog/enabling-shared-array-buffer/ for more details. (anonymous) @ stockfish.js:39

Uncaught ReferenceError: SharedArrayBuffer is not defined at stockfish.js:39 at stockfish.js:324 at stockfish.js:360

joopdegroot avatar Dec 17 '21 20:12 joopdegroot

It sounds like either your browser is too old or your server is not sending the Cross-Origin-Embedder-Policy: require-corp and Cross-Origin-Opener-Policy: same-origin headers.

server.js will set those headers.

nmrugg avatar Dec 17 '21 21:12 nmrugg

In server.js I find this comment: "Firefox needs these headers in order to handle shared array buffers for multi-threaded WASM." But the problem not only occurs in Firefox, but also in Chrome and Edge!

I also have a web server where I can try things. With the same problem as on the localhost.

joopdegroot avatar Dec 18 '21 06:12 joopdegroot

I was having the same issue and replacing stockfish.js and stockfish.wasm with the real files in src nearly fixed all my problems. I kept getting an error and the evaluation field said NNUE evaluation used, but the network file was not loaded successfully. I had to change lines 45 and 46 in enginegame.js to turn off NNUE evaluation:

uciCmd('setoption name Use NNUE value false', engine);
uciCmd('setoption name Use NNUE value false', evaler);

I could not find where the NNUE file is loaded.

tennis-aa avatar Jan 30 '22 01:01 tennis-aa

OK, it seems you made progress! But what do you mean with "replacing stockfish.js and stockfish.wasm with the real files in src"?

joopdegroot avatar Jan 30 '22 09:01 joopdegroot

I just followed the previous comment from @nmrugg :

The error message does not make sense as there is no . token in stockfish.js line 1. I'm guessing it's an issue with the symlink. Are you on Windows? It may not be able to handle it. You may need to delete the stockfish.js and stockfish.wasm files from example/ and replace them with the real files from src/.

That worked for me but I guess you already tried that and it did not work for you.

tennis-aa avatar Jan 30 '22 12:01 tennis-aa

O yes, I see. Yes, that's what I had done. I had already forgotten about it, as it was more than a month ago.

Yes, I am working in Windows. Today I copied my files to a Mac and somehow it did work there... Then I uninstalled everything again (because I had added a lot of dirt) to repeat the whole process, and... no, I am back again: both on Windows and Mac I get the same negative result.

This is how I worked: I downloaded stockfish.js-master.zip, which is a file of 28,429,494 bytes I unzip it to the Windows c:\xampp\htdocs directory, so I have c:\xampp\htdocs\stockfish.js-master then I move the files c:\xampp\htdocs\stockfish.js-master\src\stockfish.js and c:\xampp\htdocs\stockfish.js-master\src\stockfish.wasm to the folder c:\xampp\htdocs\stockfish.js-master\example
(overwriting the symlinks of the same names, stockfish.js and stockfish.wasm) so I have c:\xampp\htdocs\stockfish.js-master\example\stockfish.js (48,833 bytes) and c:\xampp\htdocs\stockfish.js-master\example\stockfish.wasm (679,336 bytes) then I run: http://localhost/stockfish.js-master/example/index.html and I get this in the browser console: enginegame.js:39 UCI: isready stockfish.js:39 [Deprecation] SharedArrayBuffer will require cross-origin isolation as of M92, around July 2021. See https://developer.chrome.com/blog/enabling-shared-array-buffer/ for more details. (anonymous) @ stockfish.js:39 stockfish.js:39 Uncaught ReferenceError: SharedArrayBuffer is not defined at stockfish.js:39 at stockfish.js:324 at stockfish.js:360 stockfish.js:39 [Deprecation] SharedArrayBuffer will require cross-origin isolation as of M92, around July 2021. See https://developer.chrome.com/blog/enabling-shared-array-buffer/ for more details. (anonymous) @ stockfish.js:39 stockfish.js:39 Uncaught ReferenceError: SharedArrayBuffer is not defined at stockfish.js:39 at stockfish.js:324 at stockfish.js:360

This is all Windows. Tried it again on a Mac. Safari console says: UCI: isready ReferenceError: Can't find variable SharedArrayBuffer

Removing lines 45 en 46 didn't work for me. Same result.

So for now the problem for me is how does that error with SharedArrayBuffer occur (on both Windows and Mac)?

joopdegroot avatar Jan 31 '22 14:01 joopdegroot

I get the same error when I open index.html from vscode's live server. But it works fine when I run the server: node example/server.js. What do you mean when you say

then I run: http://localhost/stockfish.js-master/example/index.html

?

tennis-aa avatar Feb 04 '22 01:02 tennis-aa

this is still an issue on windows; thank you for helpful comments; we ought to make a pull request to fix this

wordpad25 avatar Jun 12 '22 22:06 wordpad25

I have the same issue (in windows) it would be great to see an example working.

EE2dev avatar Nov 02 '22 01:11 EE2dev

I have the same issue (in windows) it would be great to see an example working.

It works for me now after I replaced the stockfish.js, stockfish.wasm and nn-6877cd24400e.nnue files from example/ with the real files from src/._

EE2dev avatar Nov 04 '22 23:11 EE2dev

Also after copying the .nnue file from /src to /example (overwriting the existing symlink), I still get the SharedArrayBuffer error when I run (open) example on my localhost (XAMPP - http://localhost/myStockfishText/example/index.html),

joopdegroot avatar Nov 06 '22 07:11 joopdegroot