mapbox / sphericalmercator

Spherical Mercator math in Javascript
BSD 3-Clause "New" or "Revised" License
275 stars 47 forks source link

ESM import does not work #46

Open MattIPv4 opened 3 weeks ago

MattIPv4 commented 3 weeks ago
npm init -y

npm pkg set type=module

npm i @mapbox/sphericalmercator@2

echo "import { SphericalMercator } from '@mapbox/sphericalmercator';" > index.js

node index.js
import { SphericalMercator } from '@mapbox/sphericalmercator';
         ^^^^^^^^^^^^^^^^^
SyntaxError: Named export 'SphericalMercator' not found. The requested module '@mapbox/sphericalmercator' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from '@mapbox/sphericalmercator';
const { SphericalMercator } = pkg;
mapsam commented 3 weeks ago

Shoot, this was my fault in #45! Maybe @greenlaw or @AlexanderBelokon could lend some 👀 to help remedy this in a patch release.

greenlaw commented 2 weeks ago

@MattIPv4 @mapsam PR here for your review: https://github.com/mapbox/sphericalmercator/pull/47