From b411c5bef8809438012af2ca504638970b28f704 Mon Sep 17 00:00:00 2001 From: Danielv123 Date: Sun, 11 Oct 2026 13:15:14 +0200 Subject: [PATCH] Fix running Clusterio from published packages Since the move to ES modules and pnpm 12, packages installed from npm fail to start: - The package imports of @clusterio/lib point Node at TypeScript sources, which Node refuses to strip types from inside node_modules. - The controller, host and ctl import their package.json from next to the compiled entrypoint, a copy pnpm leaves out of the package. - ctl, host and web_ui have no .npmignore, so pnpm packs them using the repository .gitignore and leaves out nearly all of dist/. Resolve the package imports to the compiled files at runtime while keeping the sources for type checking, import package.json by package name so it resolves to the real file, and add .npmignore files so pnpm packs the same files as npm. --- packages/controller/controller.ts | 2 +- packages/controller/src/WsServer.ts | 2 +- packages/ctl/.npmignore | 1 + packages/ctl/ctl.ts | 2 +- packages/host/.npmignore | 1 + packages/host/host.ts | 2 +- packages/lib/package.json | 10 ++++++++-- packages/web_ui/.npmignore | 1 + 8 files changed, 15 insertions(+), 6 deletions(-) create mode 100644 packages/ctl/.npmignore create mode 100644 packages/host/.npmignore create mode 100644 packages/web_ui/.npmignore diff --git a/packages/controller/controller.ts b/packages/controller/controller.ts index 4736aba0..ba863ae9 100644 --- a/packages/controller/controller.ts +++ b/packages/controller/controller.ts @@ -32,7 +32,7 @@ import { ConsoleTransport, levels, logger } from "@clusterio/lib"; import Controller from "./src/Controller.js"; import UserManager from "./src/UserManager.js"; import UserRecord from "./src/UserRecord.js"; -import packageConfig from "./package.json" with { type: "json" }; +import packageConfig from "@clusterio/controller/package.json" with { type: "json" }; // globals let controller: Controller; diff --git a/packages/controller/src/WsServer.ts b/packages/controller/src/WsServer.ts index db582ec1..9e5b2dd4 100644 --- a/packages/controller/src/WsServer.ts +++ b/packages/controller/src/WsServer.ts @@ -12,7 +12,7 @@ import ControlConnection from "./ControlConnection.js"; import HostConnection from "./HostConnection.js"; import WsServerConnector from "./WsServerConnector.js"; -import packageConfig from "../package.json" with { type: "json" }; +import packageConfig from "@clusterio/controller/package.json" with { type: "json" }; const wsMessageCounter = new lib.Counter( "clusterio_controller_websocket_message_total", diff --git a/packages/ctl/.npmignore b/packages/ctl/.npmignore new file mode 100644 index 00000000..5bfde2b7 --- /dev/null +++ b/packages/ctl/.npmignore @@ -0,0 +1 @@ +# Without an .npmignore pnpm packs using the repository .gitignore, which leaves out dist/ diff --git a/packages/ctl/ctl.ts b/packages/ctl/ctl.ts index 55f2d944..0de27ee7 100755 --- a/packages/ctl/ctl.ts +++ b/packages/ctl/ctl.ts @@ -7,7 +7,7 @@ import fs from "node:fs/promises"; import yargs, { type Argv } from "yargs"; import path from "path"; -import packageConfig from "./package.json" with { type: "json" }; +import packageConfig from "@clusterio/ctl/package.json" with { type: "json" }; import { strict as assert } from "assert"; // Reduce startup time by lazy compiling schemas. diff --git a/packages/host/.npmignore b/packages/host/.npmignore new file mode 100644 index 00000000..5bfde2b7 --- /dev/null +++ b/packages/host/.npmignore @@ -0,0 +1 @@ +# Without an .npmignore pnpm packs using the repository .gitignore, which leaves out dist/ diff --git a/packages/host/host.ts b/packages/host/host.ts index cd050cb0..8d31e071 100755 --- a/packages/host/host.ts +++ b/packages/host/host.ts @@ -15,7 +15,7 @@ import fs from "node:fs/promises"; import path from "path"; import yargs from "yargs"; -import packageConfig from "./package.json" with { type: "json" }; +import packageConfig from "@clusterio/host/package.json" with { type: "json" }; import winston from "winston"; import "winston-daily-rotate-file"; diff --git a/packages/lib/package.json b/packages/lib/package.json index e23c4b8c..5f6f94b3 100644 --- a/packages/lib/package.json +++ b/packages/lib/package.json @@ -25,11 +25,17 @@ "type": "module", "imports": { "#WebSocket": { - "node": "./src/link/WebSocket.node.ts", + "node": { + "types": "./src/link/WebSocket.node.ts", + "default": "./dist/node/src/link/WebSocket.node.js" + }, "import": "./src/link/WebSocket.browser.ts" }, "#is_deep_strict_equal": { - "node": "./src/is_deep_strict_equal.node.ts", + "node": { + "types": "./src/is_deep_strict_equal.node.ts", + "default": "./dist/node/src/is_deep_strict_equal.node.js" + }, "import": "./src/is_deep_strict_equal.browser.ts" } }, diff --git a/packages/web_ui/.npmignore b/packages/web_ui/.npmignore new file mode 100644 index 00000000..5bfde2b7 --- /dev/null +++ b/packages/web_ui/.npmignore @@ -0,0 +1 @@ +# Without an .npmignore pnpm packs using the repository .gitignore, which leaves out dist/