5

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?

  1. Explicitly declare exports without main
  2. Declare exports with main that would point to an index.js that 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');
Monad
  • 85
  • 3

0 Answers0