chrisveness / geodesy

Libraries of geodesy functions implemented in JavaScript
http://www.movable-type.co.uk/scripts/geodesy-library.html
MIT License
1.17k stars 203 forks source link

Please create a main field on package.json #90

Closed ScriptedAlchemy closed 2 years ago

ScriptedAlchemy commented 3 years ago

Im having some nightmare issues trying to resolve this project with next-transpile-modules

Is it possible to please add some kind of index.js file so require.resolve is able to find the package properly

ivanoats commented 3 years ago

Maybe https://github.com/chrisveness/geodesy/pull/56/ could be cleaned up.

chrisveness commented 3 years ago

The reason that I've never included a 'main' entry is that there is a range of independent entry points into the library; while one user might

import LatLon from 'geodesy/latlon-spherical.js';

or

import LatLon from 'geodesy/latlon-ellipsoidal-vincenty.js';

another user might

import Mgrs, { LatLon } from 'geodesy/mgrs.js';

I'm afraid I've no experience with Next or indeed React – why is it next-transpile-modules requires a main entry?

ScriptedAlchemy commented 3 years ago

The main field can point to an empty module export. It's just require.resolve and enhanced-handed resolve won't work without a valid field available.

chrisveness commented 3 years ago

Looking through these:

I gather that webpack respects both "main" and "module", and that "main" is more used for CommonJS and "module" for ESM ("with package.json "main" specifying the CommonJS entry point and package.json "module" specifying the ES module entry point") – and also that "module" can "point to a folder of ES modules".

So it appears to me that a package.json entry

    "module": "./"

would be correct and accurate, and would satisfy webpack's resolve requirements – have I understood well?

If so, I would be more than happy to include that.

chrisveness commented 2 years ago

I've added "module": "./" to package.json in v2.3.0, which I hope resolves this issue.

ScriptedAlchemy commented 2 years ago

Much appreciated