TypeScript setup
Install dependencies
Section titled “Install dependencies”Run these commands from your mod’s directory:
npm install --save-dev --save-exact @revomp/types-server @revomp/types-client @revomp/types-natives @revomp/types-webviewnpm install --save-dev typescript esbuild @types/node@26| Package | Provides |
|---|---|
@revomp/types-server |
The revo-server API. |
@revomp/types-client |
The revo-client API. |
@revomp/types-natives |
GTA functions imported from natives. |
@revomp/types-webview |
The WebView bridge, available as window.revo or revo. |
@revomp/types-shared |
Shared types and utilities from revo-shared. Installed automatically with the server and client declarations. |
Use declaration versions that match your multiplayer release. Keep the Revo
packages at the same version and commit package.json and the lockfile.
To select a specific version when installing, append @version to each
Revo package name.
The example uses @types/node@26 for server packages embedding Node.js 26.
Match this major version to the server’s Node.js runtime when using another
release.
Organize the source files
Section titled “Organize the source files”Use a separate tsconfig.json for each environment:
mod/ package.json package-lock.json src/ server/ tsconfig.json index.ts client/ tsconfig.json client.ts webview/ tsconfig.json main.ts server/ client/ scripts/ ui/The types and
lib settings below load
Node.js declarations for server code, client API declarations for game scripts
and browser declarations for WebViews.
Keep "type": "module" in the mod’s package.json so the generated server
.js files run as ES modules. Run the commands below from the mod’s directory.
Server
Section titled “Server”Save as src/server/tsconfig.json:
{ "compilerOptions": { "target": "ES2022", "module": "NodeNext", "moduleResolution": "NodeNext", "lib": ["ES2022"], "types": ["node", "@revomp/types-server"], "strict": true, "rootDir": ".", "outDir": "../../server", "noEmitOnError": true }, "include": ["**/*.ts"]}Build the server scripts:
npx tsc --project src/server/tsconfig.jsonThis compiles src/server/index.ts to server/index.js and preserves
subdirectories inside the source folder. Point scripting.js.entry at that
output file, relative to the server’s working directory. For example, a mod at
resources/first-mod uses resources/first-mod/server/index.js.
For relative imports between server source files, use the output .js
extension, such as import './players.js' for a source file named players.ts.
Keep runtime npm dependencies installed alongside your mod, as described in
Imports and npm dependencies.
Client
Section titled “Client”Save as src/client/tsconfig.json:
{ "compilerOptions": { "target": "ES2022", "module": "ESNext", "moduleResolution": "Bundler", "moduleDetection": "force", "lib": ["ES2022"], "types": ["@revomp/types-client", "@revomp/types-natives"], "strict": true, "isolatedModules": true, "noEmit": true }, "include": ["**/*.ts"]}Use the client build example
and change its entryPoints to ['src/client/client.ts']. Keep the output
at client/scripts/client.js and the three runtime imports in external.
Check the types, then run the build after the check succeeds:
npx tsc --project src/client/tsconfig.jsonnode build-client.mjsHere, noEmit leaves
JavaScript generation to esbuild. TypeScript checks the code, and
esbuild compiles and bundles it.
WebView
Section titled “WebView”If your frontend framework already provides a TypeScript configuration, add
@revomp/types-webview to its compilerOptions.types array and retain the
framework’s other settings and build commands.
For a WebView without a framework, save this as src/webview/tsconfig.json:
{ "compilerOptions": { "target": "ES2022", "module": "ESNext", "moduleResolution": "Bundler", "moduleDetection": "force", "lib": ["ES2022", "DOM", "DOM.Iterable"], "types": ["@revomp/types-webview"], "strict": true, "isolatedModules": true, "noEmit": true }, "include": ["**/*.ts"]}Check the types, then build after the check succeeds:
npx tsc --project src/webview/tsconfig.jsonnpx esbuild src/webview/main.ts --bundle --format=esm --platform=browser --outfile=client/ui/main.jsLoad the result from your WebView HTML with
<script type="module" src="./main.js"></script>.
In this layout, resources.pack.path points to the mod’s client directory.
The package includes the compiled client scripts and WebView files. Run the
builds before packaging resources.
Using plain JavaScript
Section titled “Using plain JavaScript”The declaration packages also provide autocomplete for .js files. The
first-mod examples select their types
with /// <reference types="..." />. Add // @ts-check if you also want type
errors reported in an individual JavaScript file.