Skip to content

Fix Ubuntu setup: add server.js, correct build instructions, add setup-ubuntu.sh#6

Draft
sriail with Copilot wants to merge 2 commits into
mainfrom
copilot/update-ubuntu-setup-instructions
Draft

Fix Ubuntu setup: add server.js, correct build instructions, add setup-ubuntu.sh#6
sriail with Copilot wants to merge 2 commits into
mainfrom
copilot/update-ubuntu-setup-instructions

Conversation

Copilot AI commented Apr 3, 2026

Copy link
Copy Markdown
Contributor

Two broken flows: node server.js failed with MODULE_NOT_FOUND because server.js was never in the repo; emcmake cmake .. failed because the repo has no CMakeLists.txt — it uses PowerShell scripts that invoke emcc directly.

Changes

server.js (new)

  • Express + ws WebSocket server; fixes the MODULE_NOT_FOUND error
  • Serves only web-build/project/emscripten/ (WASM output) and web-build/data/ (assets) — not the repo root, avoiding source-file exposure
  • Binds to 127.0.0.1 by default; override with HOST=0.0.0.0
  • WebSocket payload logging truncated to 120 chars

package.json (new)

  • Declares express ^4.18.2 and ws ^8.17.1 (patched past DoS-vulnerable 8.16.x)

setup-ubuntu.sh (new)

readme.MD (updated)

  • Replaced placeholder content with Ubuntu setup/build/serve instructions
  • Troubleshooting section covering: MODULE_NOT_FOUND, CMake confusion, missing npm, stale emsdk, missing build script
Original prompt

Update Ubuntu setup/build/serve instructions for MCPE-WASM PR #5 so that:

  1. The WebSocket server file server.js is actually created before running node server.js, avoiding MODULE_NOT_FOUND.
  2. The build instructions do not assume a top-level CMakeLists.txt exists; detect correct build system and/or build directory and adjust commands accordingly.
  3. Provide a robust bash script and README section that:
    • installs dependencies (Node.js, npm, emsdk)
    • clones repo and checks out PR branch infinite-world
    • builds the wasm output using the repo's actual build instructions
    • serves static files and runs a WebSocket server for world connection
    • includes common troubleshooting for missing CMakeLists, missing npm, and existing emsdk directory.

Context from user logs:

  • emcmake cmake .. fails: CMake Error: The source directory "/home/admin1/MCPE-WASM" does not appear to contain CMakeLists.txt.
  • node server.js fails: Error: Cannot find module '/home/admin1/MCPE-WASM/server.js'.

Acceptance criteria:

  • After following the updated commands, ls -l server.js exists and node server.js starts successfully.
  • Build step either succeeds or is conditionally skipped with clear guidance based on repo structure.

The following is the prior conversation context from the user's chat exploration (may be truncated):

User: make me a series of linux commands to build/ set this up on ubuntu and serve the repo (with websockets for world conevction

Assistant: Based on the pull request for MCPE-WASM (a Minecraft Pocket Edition WebAssembly project), here's a series of Linux commands to build and serve the repo on Ubuntu:

#!/bin/bash

# Update system packages
sudo apt update && sudo apt upgrade -y

# Install essential build tools
sudo apt install -y build-essential cmake git

# Install Node.js and npm (for serving with WebSocket support)
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt install -y nodejs

# Install Emscripten (WebAssembly toolchain)
cd ~
git clone https://github.com/emscripten-core/emsdk.git
cd emsdk
./emsdk install latest
./emsdk activate latest
source ./emsdk_env.sh

# Clone the repository
cd ~
git clone https://github.com/sriail/MCPE-WASM.git
cd MCPE-WASM

# Checkout the PR branch with infinite world changes
git fetch origin pull/5/head:infinite-world
git checkout infinite-world

# Build the project with Emscripten
mkdir -p build
cd build
emcmake cmake ..
emmake make

# Install a simple WebSocket-capable HTTP server
cd ~/MCPE-WASM
npm init -y
npm install ws express

# Create a server file for serving with WebSocket support
cat > server.js << 'EOF'
const express = require('express');
const http = require('http');
const WebSocket = require('ws');
const path = require('path');

const app = express();
const server = http.createServer(app);
const wss = new WebSocket.Server({ server });

// Serve static files
app.use(express.static(path.join(__dirname, 'build')));
app.use(express.static(__dirname));

// WebSocket connection for world data
wss.on('connection', (ws) => {
  console.log('Client connected');
  
  ws.on('message', (message) => {
    console.log('Received:', message.toString());
    // Broadcast to all connected clients (for multiplayer world sync)
    wss.clients.forEach((client) => {
      if (client !== ws && client.readyState === WebSocket.OPEN) {
        client.send(message);
      }
    });
  });

  ws.on('close', () => {
    console.log('Client disconnected');
  });
});

const PORT = process.env.PORT || 8080;
server.listen(PORT, '0.0.0.0', () => {
  console.log(`Server running on http://localhost:${PORT}`);
  console.log(`WebSocket server ready for world connections`);
});
EOF

# Make the script executable
chmod +x server.js

# Start the server
node server.js

Quick setup commands (copy-paste):

# 1. Install dependencies
sudo apt update && sudo apt upgrade -y
sudo apt install -y build-essential cmake git
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt install -y nodejs

# 2. Setup Emscripten
cd ~ && git clone https://github.com/emscripten-core/emsdk.git
cd emsdk && ./emsdk install latest && ./emsdk activate latest
source ./emsdk_env.sh

# 3. Clone and build
cd ~ && git clone https://github.com/sriail/MCPE-WASM.git
cd MCPE-WASM
git fetch origin pull/5/head:infinite-world && git checkout infinite-world
mkdir -p build && cd build
emcmake cmake .. && emmake make

# 4. Setup server
cd ~/MCPE-WASM
npm init -y
npm install ws express

# 5. Create and run the server (use the server.js code above)
# Then run:
node server.js

Access the application:

  • Open your browser to http://localhost:8080
  • WebSocket connections for world data will automatically connect to ws://localhost:8080

Notes:

  • The WebSocket server handles real-time chunk loading/unloading for the infinite world feature
  • If you need to persist world data, you'll want to add storage (e.g., Redis o...

This pull request was created from Copilot chat.

…buntu instructions

Agent-Logs-Url: https://github.com/sriail/MCPE-WASM/sessions/adf95c20-93b8-45f4-8356-420b8408499a

Co-authored-by: sriail <225764385+sriail@users.noreply.github.com>
Copilot AI changed the title [WIP] Update Ubuntu setup/build/serve instructions for MCPE-WASM PR #5 Fix Ubuntu setup: add server.js, correct build instructions, add setup-ubuntu.sh Apr 3, 2026
Copilot AI requested a review from sriail April 3, 2026 19:36
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

Successfully merging this pull request may close these issues.

2 participants