Unable to use ESM import
See original GitHub issueI’m seeing errors when importing the module into an ESM project:
import { kml } from '@tmcw/togeojson';
^^^
SyntaxError: Named export 'kml' not found. The requested module '@tmcw/togeojson' is a CommonJS module, which may not support all module.exports as named exports.
But if I use this method:
import toGeoJSON from '@tmcw/togeojson';
I see this error:
export { gpx, gpxGen, kml, kmlGen, kmlWithFolders, tcx, tcxGen };
^^^^^^
SyntaxError: Unexpected token 'export'
So I’m kinda stuck. Any idea what’s happening here? Using v5.1.2
Issue Analytics
- State:
- Created a year ago
- Comments:5
Top Results From Across the Web
Unable to import from libs using ESM · Issue #109 · remix-run ...
The following error is thrown when trying to import from libs using ESM (like unist-util-visit): Error [ERR_REQUIRE_ESM]: Must use import to load ES...
Read more >Unable to import ESM .ts module in node - Stack Overflow
It seems you are looking to use ESM with Node and TS. tsconfig.json (tested with TypeScript 4.7 and 4.8). On your tsconfig.json file...
Read more >Error [ERR_REQUIRE_ESM]: require() of ES Module not ...
You can solve the "[ERR_REQUIRE_ESM]: require() of ES Module not supported" by doing one of two things: Use ESM - use import foo...
Read more >JavaScript modules - MDN Web Docs
Use of native JavaScript modules is dependent on the import and export ... They need to be top-level items; you can't use export...
Read more >How to Bypass ES Modules Errors in Next.js with Dynamic ...
The error in the image below shows that we can't use the CommonJS approach to import a module. serialize-1. This new standard and...
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 Free
Top 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
v5.1.3 released with a fix. Changing file endings for the export from
.js
to.mjs
enables Node.js native ESM support without changing everything else. Thanks for the bug report!Yes that could fix this issue, but based on https://github.com/placemark/togeojson/issues/63#issuecomment-1061252314 it may not be that simple: