J2TS Runtime

raw JSON →
92.0.0 verified Fri May 01 auth: no javascript

Runtime library required for code transpiled by the Java2TypeScript (J2TS) transpiler. Stable version 92.0.0 provides a set of Java-like utilities (e.g., ArrayList, HashMap) for TypeScript/JavaScript environments. Release cadence is tied to the J2TS transpiler. Key differentiator: enables running Java-derived code directly on Node.js or in browsers with minimal overhead. Only use as a dependency for J2TS projects.

error Cannot find module 'j2ts-jre'
cause Package not installed or missing from package.json.
fix
Run 'npm install j2ts-jre'
error TypeError: ArrayList is not a constructor
cause Incorrect import pattern (e.g., default import instead of named import).
fix
Use 'import { ArrayList } from 'j2ts-jre''
error Module not found: Error: Can't resolve 'j2ts-jre/src/ArrayList'
cause Deep importing internal modules instead of using the main export.
fix
Import from the package root: 'import { ArrayList } from 'j2ts-jre''
gotcha Package is a runtime dependency for J2TS transpiled code. Do not manually add unless you are using the J2TS transpiler.
fix Follow J2TS documentation for setup.
breaking Breaking changes occur frequently with major version bumps due to transpiler compatibility. See J2TS changelog.
fix Upgrade both J2TS and j2ts-jre together.
deprecated Some Java methods may be deprecated in future versions. Check source for deprecation warnings.
fix Use alternative methods as indicated in documentation.
npm install j2ts-jre
yarn add j2ts-jre
pnpm add j2ts-jre

Demonstrates creating an ArrayList, adding elements, accessing by index, and iteration.

import { ArrayList } from 'j2ts-jre';

// Create an ArrayList and add elements
const list = new ArrayList<string>();
list.add('hello');
list.add('world');
console.log(list.size()); // 2

// Iterate
for (let i = 0; i < list.size(); i++) {
  console.log(list.get(i));
}