Registry / serialization / j4ts
library0.7.2jsnpmunverified

j4ts is a partial translation of the Java standard library (JRE) to JavaScript, forked from GWT's Java emulation and transpiled via JSweet. This NPM package (j4ts) provides the generated JavaScript and TypeScript definitions for use in JavaScript/TypeScript projects. Currently at version 0.7.2, it targets JSweet v2 and requires at least Java 8. It offers core Java collections, utilities, and NIO-like buffers. The package is ESM-compatible since v0.7.x. Compared to other Java-to-JS solutions (e.g., GWT, CheerpJ), j4ts is lightweight and designed for gradual migration of Java code to TypeScript. Release cadence is irregular, driven by j4ts upstream.

npm install j4ts
INSTALL
IMPORT
SIG · J4TS
J
j4ts
serializationjavascriptv0.7.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ArrayList
import { ArrayList } from 'j4ts'
const ArrayList = require('j4ts').ArrayList
ESM-only since v0.7.x; require() may not work in modern bundlers.
HashMap
import { HashMap } from 'j4ts'
import { HashMap } from 'j4ts/j4ts'
Use the package name directly, not a nested path.
HashSet
import { HashSet } from 'j4ts'
java.util.ArrayList
import { ArrayList } from 'j4ts'
import { java } from 'j4ts'; const ArrayList = java.util.ArrayList;
Types are exported as top-level symbols, not under a 'java' namespace.
Arrays
import { Arrays } from 'j4ts'
import * as j4ts from 'j4ts'; const Arrays = j4ts.Arrays;
Named import is preferred; default import works but is less common.

Demonstrates usage of core Java collections (ArrayList, HashMap, HashSet) imported from j4ts, with TypeScript generics.

import { ArrayList, HashMap, HashSet } from 'j4ts'; const list = new ArrayList<string>(); list.add('foo'); list.add('bar'); console.log(list.size()); // 2 const map = new HashMap<string, number>(); map.put('a', 1); map.put('b', 2); console.log(map.get('a')); // 1 const set = new HashSet<number>(); set.add(1); set.add(2); console.log(set.contains(1)); // true console.log(set.size()); // 2
Debug
Known issues
breakingPackage is ESM-only since v0.7.x. Older CommonJS imports will fail.
fix
Update imports to use ES module syntax: import { ... } from 'j4ts'
affects: >=0.7.0
breakingVersioning mismatch: NPM patch versions may not align with upstream j4ts releases.
fix
Check the exact j4ts version in the package's README or commit history.
affects: >=0.7.0
deprecatedJSweet v1 releases are obsolete. v0.3.x and earlier are for JSweet v1 and should not be used.
fix
Use j4ts >=0.5.0 with JSweet v2.
affects: <0.4.0
gotchaThe package does not support all Java standard library classes. Only a subset is translated.
fix
Check the j4ts GitHub repository for supported classes before migrating.
affects: all
Errors
Common errors & fixes
Cannot find module 'j4ts' or its corresponding type declarations.
Package not installed or TypeScript cannot resolve types because the package lacks a 'types' field in package.json or @types/j4ts is missing.
fix
Run `npm install j4ts` (or `yarn add j4ts`). Ensure tsconfig.json includes 'node_modules/@types' or the package's types are correctly configured.
Module not found: Can't resolve 'j4ts' in '/path/to/project'
Webpack or bundler cannot resolve j4ts because it's not installed or the module resolution is misconfigured.
fix
Confirm j4ts is in your dependencies. If using Webpack, ensure 'resolve.modules' includes 'node_modules'. Also check that the package.json's 'main' field points to the correct file (j4ts.js).
Upgrade
Version history
0.7.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
j4ts — npm install j4ts · libregistry