turf: Turf does not work with Webpack 4
I upgraded my project to Angular 6 which migrated to Webpack 4. I have a dependency on mapbox which uses turf. After the upgrade I started getting build errors like the following.
ERROR in ./node_modules/@turf/meta/index.mjs
997:15-25 Can't import the named export 'lineString' from non EcmaScript module (only default export is available)
@ ./node_modules/@turf/meta/index.mjs
@ ./src/index.js
It appears to be failing because @turf/meta uses mjs and @turf/helpers is a non mjs module. I am not sure if this is just a build configuration in Webpack that needs to be tweaked or if a correction needs to be made to turf. I looked around the Webpack issues and didn’t really see anything to help along with a fix.
Here is a repo to easily reproduce this issue.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 2
- Comments: 25 (6 by maintainers)
Commits related to this issue
- Update `@turf/invariant` to a webpack-compatible version see https://github.com/Turfjs/turf/issues/1383 — committed to Turbo87/aeroscore by Turbo87 5 years ago
- latest @turf/difference 6.0.2 doesn't work with webpack https://github.com/Turfjs/turf/issues/1383#issuecomment-434486339 — committed to zumper/nebula.gl by hugotox 4 years ago
- Fixes #1383 removed *.mjs — committed to andrewharvey/turf by DenisCarriere 6 years ago
Downgrading from @turf/difference v6.0.2 to v6.0.1 worked for me. I deleted my node_modules folder to make sure no old files hung around.
Could we get a similar fix for
@turf/invariant? Hitting a similar issue when trying to use@turf/boolean-containsHi @codeofsumit
Doing a bit of googling it looks like you can try and add this sort of rule to your webpack config
If you google
.mjs webpack4there are a bunch of similar issues elsewhere.Same here with
@turf/intersectand@turf/lineIntersectFYI: I was getting this error with @turf/difference v6.02 - I think it was fixed in 6.0.1 but was re-introduced with 6.0.2: https://github.com/Turfjs/turf/commit/b032dfc0870667e05159cab2bc0e541488dd3ef7#diff-149d2d8dd8ee68dc060406b560ff202e
I am also getting same issue with
@turf/invariantUsing create-react-app, deck.gl, nebula.gl and downgrading to 6.0.1 also worked. Is a webpack 4 fix on the horizon?
Got the problem with difference and intersect.
Also having issues with the intersects. Will this be fixed soon?
I am getting the same issue as @danwoods when trying to use
@turf/distance