question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to properly import turf on TypeScript?

See original GitHub issue

Hello, I’m stumbled weird error on TypeScript. Despite lint tells me turf.geometry() is a valid function, I get TypeError: Cannot read property 'geometry' of undefined when calling it. Is there anything I can do about it?

tsconfig

"target": "ES2020"
"module": "commonjs"
"lib": ["ES2020"]

example

// Error
import turf from '@turf/turf';
turf.geometry('Point', [20, 20])

// Safe
import { geometry } from '@turf/helpers';
geometry('Point', [20, 20])

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:5

github_iconTop GitHub Comments

2reactions
robinsummerhillcommented, Aug 4, 2022

@turf/turf does not have a default export so import turf from '@turf/turf'; is incorrect. You should do this instead import * as turf from '@turf/turf';. Then you can access all the turf functions like: turf.geometry, turf.point etc.

1reaction
tmcwcommented, Nov 9, 2022

I think this is already shown in the docs: http://turfjs.org/getting-started - there’s an example of importing all of turf using * as turf.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to import turf modules properly - javascript - Stack Overflow
How to import turf modules properly · watchman watch-del-all · Delete node_modules and freshly yarn install · Reset Metro's cache with yarn start ......
Read more >
import turf from '@turf/turf' - turf is undefined #1091 - GitHub
Correct, import * as turf from '@turf/turf' should be the correct way to import the module. v5.0+ Turf releases is using Namespace Imports...
Read more >
Getting started with Turf.js
Import your module of interest var collect = require('@turf/collect'); // or in ES6 import collect from '@turf/collect'; // And then use it collect(points, ......
Read more >
@turf/turf | Yarn - Package Manager
NOTE: Turf expects data in (longitude, latitude) order per the GeoJSON standard. Most Turf functions work with GeoJSON features. These are pieces of...
Read more >
Short TypeScript Import Paths in Angular9 - Bits and Pieces
The first thing you will notice once you add the path aliases is the clarity of import paths where we can quickly figure...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found