Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslnode 18–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
GeoJSONReader
✓ import GeoJSONReader from 'jsts/org/locationtech/jts/io/GeoJSONReader.js';
✗ const GeoJSONReader = require('jsts').io.GeoJSONReader;
JSTS delivers as ES Modules for Node.js (v14+). Direct deep imports are required for specific classes from version 1.4.0+.
GeometryFactory
✓ import GeometryFactory from 'jsts/org/locationtech/jts/geom/GeometryFactory.js';
✗ const GeometryFactory = require('jsts/org/locationtech/jts/geom/GeometryFactory');
Remember to import other geometry types (Point, Polygon, etc.) similarly if needed for the factory.
WKTReader
✓ import WKTReader from 'jsts/org/locationtech/jts/io/WKTReader.js';
For browser environments, a global `jsts` object is exposed when including the UMD build via a `<script>` tag, allowing access like `jsts.org.locationtech.jts.io.WKTReader`.
Point
✓ import Point from 'jsts/org/locationtech/jts/geom/Point.js';
Most geometry types (Point, LineString, Polygon) are imported from the `jsts/org/locationtech/jts/geom/` path.
This quickstart demonstrates reading GeoJSON input, performing a buffer operation on a point geometry, creating a new point with `GeometryFactory`, and serializing the buffered geometry back into GeoJSON using JSTS ES modules.
import GeoJSONReader from 'jsts/org/locationtech/jts/io/GeoJSONReader.js';
import GeoJSONWriter from 'jsts/org/locationtech/jts/io/GeoJSONWriter.js';
import GeometryFactory from 'jsts/org/locationtech/jts/geom/GeometryFactory.js';
import Point from 'jsts/org/locationtech/jts/geom/Point.js';
import BufferOp from 'jsts/org/locationtech/jts/operation/buffer/BufferOp.js';
// 1. Read a GeoJSON string into a JSTS Geometry object
const geoJsonInput = {
type: 'Feature',
geometry: {
type: 'Point',
coordinates: [10, 20]
},
properties: {
name: 'Example Point'
}
};
const reader = new GeoJSONReader();
const geometry = reader.read(geoJsonInput);
console.log('Original Geometry (JSTS):', geometry.toString());
// Expected: POINT (10 20)
// 2. Perform a spatial operation, e.g., buffer
const distance = 5;
const bufferOp = new BufferOp(geometry, distance);
const bufferedGeometry = bufferOp.getResultGeometry();
console.log('Buffered Geometry (JSTS):', bufferedGeometry.toString());
// Expected: POLYGON ((...))
// 3. Create a new geometry using GeometryFactory
const factory = new GeometryFactory();
// JSTS Coordinate is expected by createPoint
const newPoint = factory.createPoint(new Point.Coordinate(15, 25));
console.log('Newly Created Point (JSTS):', newPoint.toString());
// Expected: POINT (15 25)
// 4. Write a JSTS Geometry object back to GeoJSON
const writer = new GeoJSONWriter();
const bufferedGeoJson = writer.write(bufferedGeometry);
console.log('Buffered Geometry (GeoJSON):', JSON.stringify(bufferedGeoJson, null, 2));
/*
Expected output example for bufferedGeoJson (simplified):
{
"type": "Polygon",
"coordinates": [
[
[5.000..., 20.000...],
...
]
]
}
*/
Debug
Known issues
breakingJSTS is delivered as ES Modules only for Node.js (since version 1.4.0, solidified for Node.js 14+). CommonJS `require()` statements will no longer work and will result in errors.fixRefactor `require()` statements to `import` statements and use specific deep import paths, e.g., `import GeoJSONReader from 'jsts/org/locationtech/jts/io/GeoJSONReader.js'`.
affects: >=1.4.0
gotchaDirect shortcut methods like `.buffer()`, `.intersects()`, or `.union()` are not available on `Geometry` objects in the ES Modules build for Node.js. These methods are monkey-patched only into the bundled ES5 browser version.fixUse dedicated processor classes from `jsts/org/locationtech/jts/operation/` (e.g., `BufferOp`, `IntersectionOp`) or `jsts/org/locationtech/jts/algorithm/` to perform operations.
affects: All versions
gotchaDue to JavaScript's lack of function overloading, some JTS methods like `GeometryFactory.createMultiPoint` may only accept specific argument types (e.g., `Point[]`) unlike their Java counterparts.fixConsult the JSTS API documentation or JTS Javadoc to determine the exact expected argument types for methods that have overloaded signatures in Java.
affects: All versions
gotchaCalculations may throw a `TopologyException` (as a JavaScript `Error`) if precision issues arise or input geometries are invalid according to the OGC Simple Features specification.fixEnsure input geometries are valid (`geometry.isValid()`). Use `jsts/org/locationtech/jts/precision/GeometryPrecisionReducer.js` to reduce precision if needed, or validate geometries with `jsts/org/locationtech/jts/geom/Geometry.isValid()`.
affects: All versions
breakingJSTS requires Node.js version 18 or higher for execution as specified in its `engines` field. Older Node.js versions may encounter compatibility issues or fail to run.fixUpgrade your Node.js environment to version 18 or later using `nvm` or your preferred Node.js version manager.
affects: >=1.4.0 (implicitly from ESM transition), >=2.0.0 (explicitly in package.json)
Errors
Common errors & fixes
TypeError: require is not a function
Attempting to use CommonJS `require()` syntax in an ES module context or with JSTS versions that are ESM-only.
fixUse ES `import` statements with specific deep paths, e.g., `import GeoJSONReader from 'jsts/org/locationtech/jts/io/GeoJSONReader.js'`.
TopologyException: Points of linear element are not distinct.
Geometric operations failing due to invalid input geometries or floating-point precision issues.
fixValidate input geometries (`geometry.isValid()`). If valid, consider reducing precision using `new GeometryPrecisionReducer(precisionModel).reduce(geometry)`.
TypeError: Cannot read properties of undefined (reading 'buffer')
Trying to call a shortcut method (like `buffer`, `intersects`) directly on a `Geometry` object in the ES module build of JSTS, where these methods are not directly attached.
fixUse the dedicated operation classes, e.g., `import BufferOp from 'jsts/org/locationtech/jts/operation/buffer/BufferOp.js'; const buffered = new BufferOp(geometry, distance).getResultGeometry();`.
ReferenceError: jsts is not defined
In a browser environment, the `jsts` global object is not available, typically because the UMD build script was not correctly included or executed.
fixEnsure the JSTS UMD build (e.g., `jsts.min.js`) is correctly included via a `<script>` tag in your HTML before attempting to access `jsts`.
Audit
Dependencies
No dependency data recorded yet.