Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@turf/helpers version 7.0.0 - Cannot find module 'geojson' or its corresponding type declarations. #2617

Closed
BenJackGill opened this issue Jun 12, 2024 · 8 comments · Fixed by #2676
Assignees
Milestone

Comments

@BenJackGill
Copy link

BenJackGill commented Jun 12, 2024

Using @turf/helpers version 7.0.0 and I am seeing this TypeScript error during deployment:

../../node_modules/.pnpm/@turf+helpers@7.0.0/node_modules/@turf/helpers/dist/esm/index.d.ts:1:205 - error TS2307: Cannot find module 'geojson' or its corresponding type declarations.

1 import { GeoJSON, Feature, Point, Position, LineString, MultiLineString, Polygon, MultiPolygon, FeatureCollection, Geometry, GeometryCollection, GeometryObject, GeoJsonProperties, BBox, MultiPoint } from 'geojson';
                                                                                                                                                                                                              ~~~~~~~~~


Found 1 error in ../../node_modules/.pnpm/@turf+helpers@7.0.0/node_modules/@turf/helpers/dist/esm/index.d.ts:1
@BenJackGill BenJackGill changed the title Cannot find module 'geojson' or its corresponding type declarations. @turf/helpers version 7.0.0 - Cannot find module 'geojson' or its corresponding type declarations. Jun 12, 2024
@BenJackGill
Copy link
Author

Looking inside node_modules it seems that the package.json file for @turf/helpers is missing geojson. It is not installed under devDependencies or dependencies.

Workaround: I can overcome this when installing all of turf using pnpn add @turf/turf instead of just the individual package pnpn add @turf/helpers package. But I would prefer to only use individual packages so I still believe this needs fixing.

@smallsaucepan
Copy link
Member

That's no good. Will take a look at this as a priority @BenJackGill. Thanks for letting us know.

@smallsaucepan
Copy link
Member

@BenJackGill could you please share a bit more about your dev process and deployment environment? Would like to reproduce this locally so I can confirm any change fixes it.

@BenJackGill
Copy link
Author

BenJackGill commented Jun 12, 2024

I have a monorepo.

Internal packages of the monorepo are just-in-time packages that directly export TypeScript. And then I also have apps which consume those internal packages.

I have Turf installed in both the internal packages and the apps.

The app that is throwing the error is for Firebase Functions, which uses an internal package that has Turf installed inside it.

It's late here but I will try to get a minimal reproduction up for you later if that would help.

@BenJackGill
Copy link
Author

BenJackGill commented Jun 14, 2024

Here is the monorepo reproduction: https://stackblitz.com/edit/vitejs-vite-pbqflx?file=apps%2Ffunctions-admin%2Fpackage.json

The monorepo has a firebase-functions app which is using various internal packages. The internal packages are also imported between each other. For example, firebase-functions has internal package @seoturbo/schema installed which has internal package @seoturbo/types installed which has external package @turf/helpers installed.

I receive the error during deployment of the Firebase Functions.

Thanks for looking into this, if there's anything else I can I provide that would help please let me know.

@joekrill
Copy link

joekrill commented Jul 6, 2024

I think I'm seeing a similar problem with @turf/buffer. I'm not getting a typescript error, but the first parameter and return types are typed as any when they should be geojson types. This is happening whether I use @turf/buffer or @turf/turf. I also tried the same the 7.1.0-alpha.7 release and still getting any types. It seems to be only with certain packages. intersect is another that is giving me any types. Meanwhile circle, for example, exposes the correct types.

@smallsaucepan
Copy link
Member

Thanks @joekrill. Can you please attach some screenshots (presumably of your editor?) showing the incorrect and correct typings you are seeing? We're after as many examples as possible so we can narrow down the difference between packages that work right and those that don't.

@joekrill
Copy link

joekrill commented Jul 6, 2024

@smallsaucepan sure! Just in case it's relevant, I'm using a Yarn 4.3.1 Plug'n'Play in my particular project.

Here's what I'm seeing when I hover over along:

Screenshot 2024-07-06 at 3 15 24 PM

The line parameter is typed as any, but if I go to the definition it's supposed to be typed as Feature<LineString> | LineString. The return type of Feature<Point> is correct, though.


Here's he angle function:

Screenshot 2024-07-06 at 3 19 27 PM

The startPoint, midPoint, and endPoint should be of type Coord but are typed as any here.


bbox is interesting because the geojson parameter is typed as any (it should be AllGeoJSON), while the return type of BBox is correct. When I jump to the declaration file BBox is imported from geojson while the AllGeoJSON type is imported from @turf/helpers

Screenshot 2024-07-06 at 3 24 17 PM

If it helps, I looked at every export from @turf/turf to try to find example of exports that seem to be typed correctly. These all seem to be correct (note that some of these are explicitly typed as any, though - usually as a generic like FeatureCollection<any>, for example in distanceWeight):

  • bboxPolygon
  • centerMedian
  • cloneProperties
  • clusterEach
  • clusterReduce
  • clustersKmeans (this has a different problem because the KmeansProps it returns type is not exported)
  • collect
  • collectionOf
  • createBins
  • dissolve
  • distanceWeight
  • feature
  • featureCollection
  • featureOf
  • geometryCollection
  • getCluster
  • hexGrid
  • interpolate
  • isobands
  • isolines
  • kinks
  • lineString
  • lineStrings
  • moranIndex
  • multiLineString
  • multiPoint
  • multiPolygon
  • nearestNeighborAnalysis
  • point
  • points
  • polygon
  • polygons
  • quadratAnalysis
  • randomLineString
  • randomPoint
  • randomPolygon
  • randomPosition
  • sample
  • square
  • squareGrid
  • standardDeviationalEllipse
  • tesselate
  • tin
  • triangleGrid
  • voronoi

And the following are problematic in that they all have any types where they should have geojson-exported types:

  • along
  • angle
  • area
  • bbox
  • bboxClip
  • bearing
  • bezierSpline
  • booleanClockwise
  • booleanConcave
  • booleanContains
  • booleanCrosses
  • booleanDisjoint
  • booleanEqual
  • booleanIntersects
  • booleanOverlap
  • booleanParallel
  • booleanPointInPolygon
  • booleanPointOnLine
  • booleanTouches
  • booleanValid
  • booleanWithin
  • buffer
  • center
  • centerMean
  • centerOfMass
  • centroid
  • circle
  • cleanCoords
  • combine
  • concave
  • convex
  • coordAll
  • coordEach
  • coordReduce
  • destination
  • difference
  • distance
  • ellipse
  • envelope
  • explode
  • featureEach
  • featureReduce
  • findPoint
  • findSegment
  • flatten
  • flattenEach
  • flattenReduce
  • geomEach
  • geomReduce
  • geometry
  • getCoord
  • getCoords
  • getGeom
  • getType
  • greatCircle
  • intersect
  • length
  • lineArc
  • lineChunk
  • lineEach
  • lineIntersect
  • lineOffset
  • lineOverlap
  • lineReduce
  • lineSegment
  • lineSlice
  • lineSliceAlong
  • lineSplit
  • lineToPolygon
  • mask
  • midpoint
  • nearestPoint
  • nearestPointOnLine
  • nearestPointToLine
  • planepoint
  • pointGrid
  • pointOnFeature
  • pointToLineDistance
  • pointsWithinPolygon
  • polygonSmooth
  • polygonTangents
  • polygonToLine
  • polygonize
  • propEach
  • propReduce
  • rectangleGrid
  • rewind
  • rhumbBearing
  • rhumbDestination
  • rhumbDistance
  • sector
  • segmentEach
  • segmentReduce
  • shortestPath
  • tag
  • toMercator
  • toWgs84
  • union
  • unkinkPolygon

I went through them pretty quickly so hopefully this is accurate.

Let me know if there are specific exports you want to see, or anything else I can provide.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants