stockfish.js
stockfish.js copied to clipboard
Syntax error in stockfish.js
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.
Hmmm.... @joopdegroot, what browser are you using?
I use Chrome (But in FireFox it's the same problem.) I work in Windows.
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 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
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.
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.
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.
OK, it seems you made progress! But what do you mean with "replacing stockfish.js and stockfish.wasm with the real files in src"?
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 thestockfish.js
andstockfish.wasm
files fromexample/
and replace them with the real files fromsrc/
.
That worked for me but I guess you already tried that and it did not work for you.
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)?
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
?
this is still an issue on windows; thank you for helpful comments; we ought to make a pull request to fix this
I have the same issue (in windows) it would be great to see an example working.
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/._
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),