Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[package.json] exposes types to npm #41

Merged
merged 1 commit into from
Jan 17, 2023
Merged

[package.json] exposes types to npm #41

merged 1 commit into from
Jan 17, 2023

Conversation

Ayc0
Copy link
Contributor

@Ayc0 Ayc0 commented Jan 16, 2023

Description

Fixes #32

Changes

As described in https://www.typescriptlang.org/docs/handbook/esm-node.html, we need to expose types in 2 fields:

  • top level, for CJS fall-back for older versions of Node.js
  • in the exports field, as entry-point for TypeScript resolution - must occur first!
// package.json
{
    "name": "my-package",
    "type": "module",
    "exports": {
        ".": {
            // Entry-point for TypeScript resolution - must occur first!
            "types": "./types/index.d.ts",
            // Entry-point for `import "my-package"` in ESM
            "import": "./esm/index.js",
            // Entry-point for `require("my-package") in CJS
            "require": "./commonjs/index.cjs",
        },
    },
    // CJS fall-back for older versions of Node.js
    "main": "./commonjs/index.cjs",
    // Fall-back for older versions of TypeScript
    "types": "./types/index.d.ts"
}

@LeaVerou LeaVerou merged commit 6f842fd into LeaVerou:master Jan 17, 2023
@LeaVerou
Copy link
Owner

Thanks!

@Ayc0 Ayc0 deleted the Ayc0/package.json branch January 17, 2023 12:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Type Definitions file index.d.ts not being published
2 participants