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

Next.js + TypeScript - Error TS7016

Fedec96 opened this issue · comments

Component Version
Turf 6.5.0
Next.js 14.1.0
TypeScript 5.3.3

This simple import is not working:

import * as turf from "@turf/turf";

I'm getting the following error:

There are types at '/home/user/project/node_modules/@turf/turf/index.d.ts', but this result could not be resolved when respecting package.json "exports". The '@turf/turf' library may need to update its package.json or typings. ts(7016)

I installed Turf with this line:

npm i @turf/turf

Here's my tsconfig.json:

{
  "compilerOptions": {
    "target": "es2015",
    "lib": ["dom", "dom.iterable", "esnext"],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": true,
    "noEmit": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "bundler",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve",
    "incremental": true,
    "plugins": [
      {
        "name": "next"
      }
    ],
    "paths": {
      "@/*": ["./src/*"]
    }
  },
  "include": [
    "next-env.d.ts",
    "process.d.ts",
    "next-auth.d.ts",
    "mantine-colors.d.ts",
    "**/*.ts",
    "**/*.tsx",
    ".next/types/**/*.ts"
  ],
  "exclude": ["node_modules"]
}

Any help is appreciated.
Thanks!

Please try the latest 7.x alpha version

same issue... resolved with 7.x alpha version.
this is because the exports entry of the package.json does not include the index.d.ts file

if you need to stay in 6.x version
as a workaround you can copy paste your ./node_modules/@turf/turf/index.d.ts file in your project directory

cp ./node_modules/@turf/turf/index.d.ts turd.d.ts`

and surrounds its content with a local module declaration

// turf.d.ts
module "@turf/turf" {
  // all the content of original index.d.ts
  /**
   * Turf is a modular geospatial analysis engine written in JavaScript. It performs geospatial
   * processing tasks with GeoJSON data and can be run on a server or in a browser.
   *
   * @module turf
   * @summary Geospatial analysis for JavaScript
   */
  export { default as isolines } from "@turf/isolines";
  export { default as convex } from "@turf/convex";
  export { default as pointsWithinPolygon } from "@turf/points-within-polygon";
  // etc ...
}

not ideal...