question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unnecesary dependencies brought along with jsts-es

See original GitHub issue

In modules @turf/buffer, @turf/difference, @turf/intersect and @turf/union, modules from jsts-es are imported from the main module. E.g. in turf buffer:

import { BufferOp, GeoJSONReader, GeoJSONWriter } from 'jsts-es';

It turns out that in jsts-es/index.js, when every submodule is exported

export * from './src/org/locationtech/jts/geom'
export * from './src/org/locationtech/jts/algorithm'
export * from './src/org/locationtech/jts/densify'
export * from './src/org/locationtech/jts/dissolve'
export * from './src/org/locationtech/jts/geomgraph'
export * from './src/org/locationtech/jts/index'
export * from './src/org/locationtech/jts/io'
export * from './src/org/locationtech/jts/noding'
export * from './src/org/locationtech/jts/operation'
export * from './src/org/locationtech/jts/precision'
export * from './src/org/locationtech/jts/simplify'
export * from './src/org/locationtech/jts/triangulate'
export * from './src/org/locationtech/jts/linearref'

there are side effects that result in the whole (or most part) of jsts-es being brought along the required modules.

If I build @turf/buffer using rollup to ES6 module output, the final size is 898K and the module includes (for example), JSTS definitions for classes (to name a few) DouglasPeuckerLineSimplifier, MonoValentEndPointBoundaryNodeRule, ConformingDelaunayTriangulationBuilder, and many more that are not used at all by the Buffering operation.

If I instead require the modules directly as:

import GeoJSONReader from 'jsts-es/src/org/locationtech/jts/io/GeoJSONReader.js';
import GeoJSONWriter from 'jsts-es/src/org/locationtech/jts/io/GeoJSONWriter.js';
import {
    BufferOp
} from 'jsts-es/src/org/locationtech/jts/operation/buffer.js';

The bundle size drops to 515Kb

Now, I don’t know if this is due to my rollup.config.js being misconfigured, But I’m pretty convinced this is because JSTS structure is somehow breaking Rollup’s tree shaking.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
DenisCarrierecommented, Nov 21, 2017

JSTS has big problems when making it ES Module & CJS compatible.

The other major issue I found was the extend() method that JSTS uses copies the entire section of that source code. For example if we have 4 Turf modules that use JSTS, that means we will have 4x GeoJSONReader source code in the final Rollup bundle.

To solve this, I’ve been working on refactoring JSTS for the sole purpose of importing it in TurfJS.

https://github.com/DenisCarriere/turf-jsts

Once it’s complete I’ll replace the jsts-es module with that new code base.

0reactions
mfedderlycommented, Aug 3, 2021

We’re on turf-jsts at this point, going to close this ticket out.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is there a simple way to remove unused dependencies from a ...
Another thing that might help to do some cleanup is the Dependency Convergence report from the Maven Project Info Reports Plugin. Share.
Read more >
Stricter unused dependency checking for plus one deps mode
When using plus one deps mode, many unused deps do get marked, but some deps can be left out because they are already...
Read more >
Transitive Dependency - an overview | ScienceDirect Topics
Note: Transitive dependencies take their name from the transitive property in mathematics, which states that if a > b and b > c,...
Read more >
Intellij keeps old dependencies : IDEA-255594 - YouTrack
Whenever I update the version of a dependency in the pom.xml, Intellij keeps the old versions in the project. Removing them manually doesn't...
Read more >
A Longitudinal Analysis of Bloated Java Dependencies - arXiv
ABSTRACT. We study the evolution and impact of bloated dependencies in a single software ecosystem: Java/Maven. Bloated dependencies are.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found