Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot import d3-geo in node with typescript #261

Closed
sardounis opened this issue Jun 15, 2022 · 8 comments
Closed

Cannot import d3-geo in node with typescript #261

sardounis opened this issue Jun 15, 2022 · 8 comments

Comments

@sardounis
Copy link

sardounis commented Jun 15, 2022

It seems I have an issue of importing the library using nodejs 14 and typescript.

I have used @types/d3-geo as well.

Though I am getting the error: An unexpected error occurred Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /Users/antonissardounis/Projects/beat/bhs-cf/functions_new/functions/node_modules/d3-geo/src/index.js\nrequire() of ES modules is not supported.\nrequire() of /Users/antonissardounis/Projects/beat/bhs-cf/functions_new/functions/node_modules/d3-geo/src/index.js from /Users/antonissardounis/Projects/beat/bhs-cf/functions_new/functions/lib/utils/Geo/Geo.js is an ES module file as it is a .js file whose nearest parent package.json contains \"type\": \"module\" which defines all .js files in that package scope as ES modules.\nInstead rename index.js to end in .cjs, change the requiring code to use import(), or remove \"type\": \"module\" from /Users/antonissardounis/Projects/beat/bhs-cf/functions_new/functions/node_modules/d3-geo/package.json.\n\n at new NodeError (internal/errors.js:322:7)\n at Object.Module._extensions..js (internal/modules/cjs/loader.js:1102:13)\n at Module.load (internal/modules/cjs/loader.js:950:32)\n at Function.Module._load (internal/modules/cjs/loader.js:790:12)\n at Module.require (internal/modules/cjs/loader.js:974:19)\n at require (internal/modules/cjs/helpers.js:101:18)\n at /Users/antonissardounis/Projects/beat/bhs-cf/functions_new/functions/lib/utils/Geo/Geo.js:33:75\n at processTicksAndRejections (internal/process/task_queues.js:95:5)\n at async Geo.init (/Users/antonissardounis/Projects/beat/bhs-cf/functions_new/functions/lib/utils/Geo/Geo.js:33:27)\n at async Geo.AreCoordinatesInsideGeofence (/Users/antonissardounis/Projects/beat/bhs-cf/functions_new/functions/lib/utils/Geo/Geo.js:39:9) {\n code: 'ERR_REQUIRE_ESM'\n}"}

it seems there is an open issue at stack overflow as well: link

@Fullstack-WEB-Blockchain-Developer
Copy link

@sardounis Did you solve this issue?
I have same issue now
(I am useing node lts version)

@Toolenaar
Copy link

downgrading to v2.0.1 worked for me

@razzeee
Copy link

razzeee commented Nov 12, 2022

More people with this problem here yanivam/react-svg-worldmap#135

@bennoinbeta
Copy link

any updates on this?

@bennoinbeta
Copy link

bennoinbeta commented Feb 24, 2023

ok my mistake.. I didn't import it as namespace :)

// index.ts
import * as d3Geo from 'd3-geo'

// compiled index.js
const d3Geo = require('d3-geo')

@bennoinbeta
Copy link

bennoinbeta commented Feb 26, 2023

ok the esmodule import via import * as d3Geo from 'd3-geo' only works with 2.0.2 but not with the latest one 3.1.0 :/

@Fil
Copy link
Member

Fil commented Feb 27, 2023

this works for me:

d3Geo = await import("d3-geo");

@bennoinbeta
Copy link

yeah but dynamic imports aren't that nice.. so I'll stick to the 2.x.x for now :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

7 participants