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

multiplayer tutorial crashes with node v22 and v23. Use v21 as workaround OR make a few changes and don't use -r esm. #1200

Open
Henddher opened this issue Nov 15, 2024 · 3 comments

Comments

@Henddher
Copy link

FYI

I followed the multiplayer tutorial but npm run serve crashes.

I was able to bypass the crash by using node v21 and v20. I didn't try any older version.


The crash happens in node itself and only when using v23, and v22. @Thomblin posted the crash in esm but the project was archived on Nov 4th, 2024. It will be appropriate to follow up with node folks and the newly assertion added a few months ago here

❯ npm run serve

> [email protected] serve
> node -r esm src/server.js

  #  node[89389]: void node::fs::InternalModuleStat(const FunctionCallbackInfo<v8::Value> &) at ../src/node_file.cc:1043
  #  Assertion failed: (args.Length()) >= (2)

----- Native stack trace -----

 1: 0x104906800 node::Assert(node::AssertionInfo const&) [/Users/henddher/.nvm/versions/node/v23.2.0/bin/node]
 2: 0x1066f1444 node::fs::InternalModuleStat(v8::FunctionCallbackInfo<v8::Value> const&) (.cold.3) [/Users/henddher/.nvm/versions/node/v23.2.0/bin/node]
...
48: 0x1048c4dfc node::Start(int, char**) [/Users/henddher/.nvm/versions/node/v23.2.0/bin/node]
49: 0x182853154 start [/usr/lib/dyld]

----- JavaScript stack trace -----

1: /Users/henddher/Documents/github/bgio-tutorial/node_modules/esm/esm.js:1:34535
2: /Users/henddher/Documents/github/bgio-tutorial/node_modules/esm/esm.js:1:34176
...
9: e (/Users/henddher/Documents/github/bgio-tutorial/node_modules/esm/esm.js:1:262673)
10: get (/Users/henddher/Documents/github/bgio-tutorial/node_modules/esm/esm.js:1:262740)

zsh: abort      npm run serve
@Henddher
Copy link
Author

Henddher commented Nov 15, 2024

If you use nvm:

nvm install 21
nvm use 21
...
npm run serve
npm start

npm start produces this warning right before "Starting the development server". Nonetheless, it all seems to work "ok".

(node:21692) [DEP_WEBPACK_DEVASERVER_ON_AFTER_SETUP_MIDDLEWARE] DeprecationWarning: 'onAfterSetupMiddleware' option is deprecated. Please use the 'setupMiddlewa res' option.
(Use 'node --trace-deprecation"!
..' to show where the warning was created)
(node: 21692) [DEP_WEBPACK_DEVISERVER_ON_BEFORE_SETUP_MIDDLEWARE] DeprecationWarning: 'onBeforeSetupMiddleware' option is deprecated. Please use the 'setupMiddle wares' option.

@Henddher
Copy link
Author

Henddher commented Nov 17, 2024

After a few minor changes, it all works with node v23.2.0. No need to use --require esm when running the server.

diff --git a/package.json b/package.json
index e16e5cb..5e0e655 100644
--- a/package.json
+++ b/package.json
@@ -18,7 +18,7 @@
     "build": "react-scripts build",
     "test": "react-scripts test",
     "eject": "react-scripts eject",
-    "serve": "node -r esm src/server.js"
+    "serve": "node src/server.js"
   },
   "eslintConfig": {
     "extends": [
diff --git a/src/Game.js b/src/Game.js
index cd503b8..d08fbd7 100644
--- a/src/Game.js
+++ b/src/Game.js
@@ -1,4 +1,4 @@
-import { INVALID_MOVE } from 'boardgame.io/core';
+import { INVALID_MOVE } from 'boardgame.io/dist/esm/core.js';
 
 export const TicTacToe = {
     name: 'tic-tac-toe',
diff --git a/src/server.js b/src/server.js
index c7276bb..3d9f0a0 100644
--- a/src/server.js
+++ b/src/server.js
@@ -1,5 +1,5 @@
-const { Server, Origins } = require('boardgame.io/server');
-const { TicTacToe } = require('./Game');
+import { Server, Origins } from 'boardgame.io/dist/cjs/server.js';
+import { TicTacToe } from './Game.js';
 
 const server = Server({
     games: [TicTacToe],

Disclaimer: I'm no a node expert so take these changes with a grain of salt. Especially, the hardcoded dist path changes.

@Henddher Henddher changed the title multiplayer tutorial crashes with node v22 and v23. Use v21 as workaround. multiplayer tutorial crashes with node v22 and v23. Use v21 as workaround OR make a few changes and don't use esm. Nov 17, 2024
@Henddher Henddher changed the title multiplayer tutorial crashes with node v22 and v23. Use v21 as workaround OR make a few changes and don't use esm. multiplayer tutorial crashes with node v22 and v23. Use v21 as workaround OR make a few changes and don't use -r esm. Nov 17, 2024
@Thomblin
Copy link

Thanks for adding me here @Henddher
So far I am only able to run the server and client using nvm v9 ...

Your patch helped to run the server and actually I am able to run server and client now with the latest version
nvm 23.2.0 and npm 10.9.0

Thank you!

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

2 participants