Turfjs / turf

A modular geospatial engine written in JavaScript and TypeScript

Home Page:https://turfjs.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Could not find a declaration file for module '@turf..."

wjlee2020 opened this issue · comments

Please provide the following when reporting an issue:

  • The version of Turf you are using, and any other relevant versions.
    "@turf/helpers": "^6.5.0",
    "@turf/simplify": "^6.5.0"

  • Snippet of source code or for complex examples use jsfiddle.

import simplify from "@turf/simplify";
const turf = require("@turf/helpers");

when using an import statement, i get Could not find a declaration file for module '@turf/simplify'. ts error.
It's the same with all other modules even @turf/turf.

Any ideas/tips?

Thanks for raising the issue @wjlee2020 . I'm working on a PR at the moment that should improve the declarations that are shipped. Would you be happy to give that a try once the next v7.0.0-alpha is released?

The only shorter term option I can think of would be to edit or patch the files already installed in your node_modules/ folder - not ideal.

@wjlee2020 can you please provide some more info about your environment? Vanilla node app, NextJS, Vite? Does the error appear in VSCode, or does it only show up when you're building? Any other details would be a help to reproduce the problem and also make sure the PR fixes it. Thanks!

@smallsaucepan I apologize for the lack of details

Environment - NextJS ("13.5.6")
Error appears in VSCode - Yes
Build fails due to typescript error (error: Could not find a declaration file for module '@turf/turf')

Currently, I have made a turf.d.ts file with:

declare module "@turf/turf" {
  export function point(coordinates: number[]): any;
  export function polygon(coordinates: [number, number][][][]): any;
  export function booleanPointInPolygon(point: any, polygon: any): boolean;
}

to help me remove the typescript errors for the turf modules I am using.

import { booleanPointInPolygon, point, polygon } from "@turf/turf";

Please let me know if you would like more information 🙇🏻‍♂️

I am having this problem too with svelte kit 2.0.0 and svelte 4.2.7, turf 6.5 and typescript 5.. Resolving this by editing the tsconfig.json by adding the "moduleResolution" : "node" and the turf loads.

I faced this issue today trying to use turf in a vite/react project. Following #2521 (comment) resolves my issue. I'm using the latest alpha turf, 7.0.0-alpha.114

Same issue here, upgrading to v7 also fixed this for me