Skip to content

Choosing an engine version

The slim loader from epanet-js/slim lets you choose any of the published EPANET engines at runtime, instead of using the v2.3.5 build embedded in the default Workspace. Use this when you want:

  • A smaller bundle that ships only the engine binary you actually need.
  • Deterministic version loading** for reproducible results.
  • Compare results across engine versions.
  • An EPANET version other than v2.3.5 with MSX support (via the -msx engine variants — see the MSX example).
import { Workspace } from "epanet-js/slim";
import { Project } from "epanet-js";
import { EpanetEngine } from "epanet-js/engines/v2.3.3";
const ws = new Workspace();
await ws.loadModuleVersion(() => Promise.resolve(EpanetEngine));
const project = new Project(ws);
ws.writeFile("net.inp", inpText);
project.open("net.inp", "report.rpt", "out.bin");
project.solveH();
project.report();
const report = ws.readFile("report.rpt");
project.close();

A few notes:

  • loadModuleVersion takes a callback that returns a promise resolving to the engine module. The simplest form wraps a static import as above.
  • The callback must be imported from the package epanet-js/engines/<version>. This package holds the code to find the WASM asset next to the JS glue code. Most bundlers (Vite, Webpack 5, Rspack, esbuild) handle the WASM emission automatically.
Import pathEPANET versionMSX
epanet-js/engines/v2.22.2
epanet-js/engines/v2.32.3.0
epanet-js/engines/v2.3.1v2.3.52.3.1 – 2.3.5
epanet-js/engines/masterOWA master snapshot
epanet-js/engines/devOWA dev snapshot
epanet-js/engines/v2.2-msx2.2
epanet-js/engines/v2.3-msx2.3.0
epanet-js/engines/v2.3.1-msxv2.3.5-msx2.3.1 – 2.3.5
epanet-js/engines/master-msxOWA master snapshot
epanet-js/engines/dev-msxOWA dev snapshot

A common use case is verifying a simulation against an older EPANET version:

import { Workspace } from "epanet-js/slim";
import { Project } from "epanet-js";
async function runOn(version: string, inpText: string) {
const ws = new Workspace();
await ws.loadModuleVersion(() => import(`epanet-js/engines/${version}`));
const project = new Project(ws);
ws.writeFile("net.inp", inpText);
project.open("net.inp", "report.rpt", "out.bin");
project.solveH();
project.report();
const report = ws.readFile("report.rpt");
project.close();
return { version: ws.version, report };
}
const [v22, v235] = await Promise.all([
runOn("v2.2", inpText),
runOn("v2.3.5", inpText),
]);

The Project methods you can call depend on the engine that was loaded. You will find a badge showing which is the minimum required engine version needed for each function on the project functions page. Calling a function the loaded engine doesn’t support will throw an exception.