Skip to content

The package.json is missing the main or exports fields #889

@oleksandr-danylchenko

Description

@oleksandr-danylchenko

Issue

The package.json doesn't filter what files should be packaged and sent the NPM. Therefore, all the source code with .less files is being distributed.

Also, the entry point of the package is not specified using main, module, or exports. That way, it's confusing for the bundlers what should be used and usually they start picking the files from the src:

export { Timeline } from './src/js/index.js';

So it requires to double-transpile the package in the consuming app and they don't benefit from the transpilation done before publishing anyway 😢

Suggested changes

  1. Limit the distributed code only to the dist folder. That will significantly reduce the size of the package.
  2. Specify an entry point explicitly and it should point to the transpiled files in the dist.

Smth like this[^1]:

{
  "name": "@knight-lab/timelinejs",
  "version": "4.0.0",
  "type": "module",
  "files": [
    "dist"
  ],
  "exports": {
    ".": {
      "import": "./dist/index.js"
    }
  },
  "main": "./dist/index.js",
  ...  
Config breakdown

Node has already come up with the following package.json properties that allow to limit what will get published to NPM:

  • files - "an array of file patterns that describes the entries to be included when your package is installed as a dependency"
  • main - "a module ID that is the primary entry point to your program. That is, if your package is named foo, a user installs it, and then does require("foo")"
  • types - Set the types property to point to your bundled declaration file.
  • exports - "defining the entry points of a package. An alternative to the "main" that can support defining "subpath exports" and "conditional exports".

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions