You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm working on a new node project with typescript and I'm getting stuck when trying to import the geodesy module.
I've been doing some research before deciding to write here but I wasn't able to solve the issue.
node 15.0.1
geodesy 2.2.2
this is how I'm importing the lib: import LatLon from "geodesy/latlon-ellipsoidal-vincenty.js";
and this is the error the compiler gives me:
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /Users/brein/projects/msfs/msfs-airports-api/node_modules/geodesy/latlon-ellipsoidal-vincenty.js
require() of ES modules is not supported.
require() of /Users/brein/projects/msfs/msfs-airports-api/node_modules/geodesy/latlon-ellipsoidal-vincenty.js from /Users/brein/projects/msfs/msfs-airports-api/src/database/index.ts 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.
Instead rename latlon-ellipsoidal-vincenty.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /Users/brein/projects/msfs/msfs-airports-api/node_modules/geodesy/package.json.
at new NodeError (node:internal/errors:258:15)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1100:13)
at Module.load (node:internal/modules/cjs/loader:948:32)
at Function.Module._load (node:internal/modules/cjs/loader:789:14)
at Module.require (node:internal/modules/cjs/loader:972:19)
at require (node:internal/modules/cjs/helpers:88:18)
at Object.<anonymous> (/Users/brein/projects/msfs/msfs-airports-api/src/database/index.ts:2:1)
at Module._compile (node:internal/modules/cjs/loader:1083:30)
at Module.m._compile (/Users/brein/projects/msfs/msfs-airports-api/node_modules/ts-node/src/index.ts:1043:23)
at Module._extensions..js (node:internal/modules/cjs/loader:1112:10)
I found similar issues where the solution was to use esm to import modules, but according to the README:
The library can be loaded from npm to be used in a Node.js app (in Node.js v13.2.0+, or using the esm package in v8.0.0–v12.15.0*)
so after doing some more research I found out I had to add type: module in package.json but then it felt like opening pandora's box as it looks like ts-node is not fully supporting esm modules :(
I'm working on a new node project with typescript and I'm getting stuck when trying to import the geodesy module.
I've been doing some research before deciding to write here but I wasn't able to solve the issue.
this is how I'm importing the lib:
import LatLon from "geodesy/latlon-ellipsoidal-vincenty.js";
and this is the error the compiler gives me:
I found similar issues where the solution was to use esm to import modules, but according to the README:
and to this:
#79 (comment)
since I'm using node 15 it should just work... or am I missing something?
PS: I tried also installing esm and launch with
ts-node -r esm
just to get a different errorThe text was updated successfully, but these errors were encountered: