I plan to publish a JavaScript library as an npm package and I have a question regarding packages entry points and best practices: what would be the best practice when a package doesn't expose a single entry point?
- Explicitly declare
exportswithoutmain - Declare
exportswithmainthat would point to anindex.jsthat would throw some helpful error message explaining how to consume the lib
My lib only is only compatible with node > 14 and we use the exports property to leverage subpath exports (as it's shipped both as ESM/CJS module format)
As declared, the library doesn't expose a single entry point and is meant to be consumed by importing a default export from a specific file. So the consumer would use the following semantics to import:
// ESM
import Foo from 'my-lib/path/filename1';
// CJS
const Foo = require('my-lib/path/filename1');