Turfjs / turf

A modular geospatial engine written in JavaScript and TypeScript
https://turfjs.org/
MIT License
9k stars 925 forks source link

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

Open BenJackGill opened 3 weeks ago

BenJackGill commented 3 weeks ago

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 commented 3 weeks ago

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 commented 3 weeks ago

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

smallsaucepan commented 3 weeks ago

@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 commented 3 weeks ago

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 commented 3 weeks ago

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 commented 1 day ago

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 commented 1 day ago

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 commented 23 hours ago

@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):

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

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.