{"id":25774,"library":"j4ts","title":"j4ts","description":"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.","status":"active","version":"0.7.2","language":"javascript","source_language":"en","source_url":"https://github.com/j4ts/j4ts","tags":["javascript","java","jre","jdk","jsweet","java to javascript","typescript"],"install":[{"cmd":"npm install j4ts","lang":"bash","label":"npm"},{"cmd":"yarn add j4ts","lang":"bash","label":"yarn"},{"cmd":"pnpm add j4ts","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"ESM-only since v0.7.x; require() may not work in modern bundlers.","wrong":"const ArrayList = require('j4ts').ArrayList","symbol":"ArrayList","correct":"import { ArrayList } from 'j4ts'"},{"note":"Use the package name directly, not a nested path.","wrong":"import { HashMap } from 'j4ts/j4ts'","symbol":"HashMap","correct":"import { HashMap } from 'j4ts'"},{"note":"","wrong":"","symbol":"HashSet","correct":"import { HashSet } from 'j4ts'"},{"note":"Types are exported as top-level symbols, not under a 'java' namespace.","wrong":"import { java } from 'j4ts'; const ArrayList = java.util.ArrayList;","symbol":"java.util.ArrayList","correct":"import { ArrayList } from 'j4ts'"},{"note":"Named import is preferred; default import works but is less common.","wrong":"import * as j4ts from 'j4ts'; const Arrays = j4ts.Arrays;","symbol":"Arrays","correct":"import { Arrays } from 'j4ts'"}],"quickstart":{"code":"import { ArrayList, HashMap, HashSet } from 'j4ts';\n\nconst list = new ArrayList<string>();\nlist.add('foo');\nlist.add('bar');\nconsole.log(list.size()); // 2\n\nconst map = new HashMap<string, number>();\nmap.put('a', 1);\nmap.put('b', 2);\nconsole.log(map.get('a')); // 1\n\nconst set = new HashSet<number>();\nset.add(1);\nset.add(2);\nconsole.log(set.contains(1)); // true\nconsole.log(set.size()); // 2","lang":"typescript","description":"Demonstrates usage of core Java collections (ArrayList, HashMap, HashSet) imported from j4ts, with TypeScript generics."},"warnings":[{"fix":"Update imports to use ES module syntax: import { ... } from 'j4ts'","message":"Package is ESM-only since v0.7.x. Older CommonJS imports will fail.","severity":"breaking","affected_versions":">=0.7.0"},{"fix":"Check the exact j4ts version in the package's README or commit history.","message":"Versioning mismatch: NPM patch versions may not align with upstream j4ts releases.","severity":"breaking","affected_versions":">=0.7.0"},{"fix":"Use j4ts >=0.5.0 with JSweet v2.","message":"JSweet v1 releases are obsolete. v0.3.x and earlier are for JSweet v1 and should not be used.","severity":"deprecated","affected_versions":"<0.4.0"},{"fix":"Check the j4ts GitHub repository for supported classes before migrating.","message":"The package does not support all Java standard library classes. Only a subset is translated.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Run `npm install j4ts` (or `yarn add j4ts`). Ensure tsconfig.json includes 'node_modules/@types' or the package's types are correctly configured.","cause":"Package not installed or TypeScript cannot resolve types because the package lacks a 'types' field in package.json or @types/j4ts is missing.","error":"Cannot find module 'j4ts' or its corresponding type declarations."},{"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).","cause":"Webpack or bundler cannot resolve j4ts because it's not installed or the module resolution is misconfigured.","error":"Module not found: Can't resolve 'j4ts' in '/path/to/project'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}