How to properly import turf on TypeScript?
See original GitHub issueHello, 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:
- Created a year ago
- Comments:5
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@turf/turf does not have a default export so
import turf from '@turf/turf';
is incorrect. You should do this insteadimport * as turf from '@turf/turf';
. Then you can access all the turf functions like:turf.geometry
,turf.point
etc.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
.