-
-
Notifications
You must be signed in to change notification settings - Fork 9
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
"<script src="stockfish.js"></script>" vs. "import Stockfish from 'stockfish'" #12
Comments
Hi. Did you already have a look at the demo https://github.com/ianfab/fairy-stockfish-nnue-wasm-demo? I hope that should help to get started. |
Hi @ianfab, thank you for writing back to me! I spent some time with the demo yesterday and today. By reusing the code found there, it's possible for me to create a new html file (
<html>
<body>
<script src="./lib/stockfish.js"></script>
<script>
(async () => {
let stockfish = null;
await Stockfish().then(_stockfish => {
stockfish = _stockfish;
stockfish.addMessageListener(console.log);
});
stockfish.postMessage("uci");
})()
</script>
</body>
</html> Opening This is really, really cool, and I'm trying to get it to work inside of a Next.js project (created with The problem is that I get strange errors if I try to import it using ES6 syntax, i.e Do you maybe have some advice on how I could proceed? Perhaps it's more appropriate to post this elsewhere? :) ...could I maybe use a worker that talks to Fairy Stockfish? |
An update on using a worker: If <html>
<body>
<script>
const worker = new Worker('./worker.js');
</script>
</body>
</html> and importScripts("./lib/stockfish.js");
let stockfish = null;
Stockfish().then(_stockfish => {
stockfish = _stockfish;
stockfish.addMessageListener(console.log);
}) Then the console will output the following error (formatting changed):
|
Working solution: "use client"
import React, { useEffect } from 'react';
export default function Component() {
useEffect(() => {
// @ts-ignore
console.log(Stockfish)
});
return (
<React.Fragment>
<script src="lib/stockfish.js"></script>
{ /* other things go here... */ }
</React.Fragment>
);
} It is possible to include a Is this a good solution? I'm really confused as to why it has to be done this way. |
The pure Javascript code example two posts up by @sombor-shuffle should be the official documentation IMHO, the basic demo site and the fairyland demo site are both too mixed in with frameworks that the user probably won't be using. |
Hey @zeth, I realized later that the I agree that the basic demo could be more accessible and I wouldn't mind re-writing it in plain js, if there is any enthusiasm for it. It wouldn't be terrible at all if you could |
Working Solution for stockfish.js, didn't try fairystockfish Put stockfish.js in public folder of next.js app Very important then this should work
for more advanced example https://react-chessboard.vercel.app/?path=/docs/stockfishintegration--docs if any one has solution to removing stockfish.js out of public this would be good |
Hello! I'm trying to use Fairy Stockfish inside of a Next.js project.
I installed the npm package fairy-stockfish-nnue.wasm.
Now, placing
<script src="stockfish.js"></script>
and then referencingStockfish
inside of another script element works just fine:However, it remains inaccessible to the rest of my application. This lead me to try to
import Stockfish from 'stockfish'
. Sadly, usingStockfish
now leads to an error:console.log(Stockfish)
givesModule not found: Can't resolve 'fs'
.Looking inside of stockfish.js, I can see that "fs" is indeed used, and from here on out I don't know how to proceed.
Any pointers to what I should do to be able to use Fairy Stockfish? :)
The text was updated successfully, but these errors were encountered: