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

fix: fix missing ESM type definition file #67

Merged
merged 1 commit into from
Jul 30, 2023

Conversation

mizdra
Copy link
Contributor

@mizdra mizdra commented Jul 30, 2023

Background

The dedent package exports only CJS type definition files (./dist/index.d.ts). Therefore, if users try to import dedent as an ESM, tsc will not find the type definition file.

How to reproduction:

$ git clone https://github.com/mizdra/reproduction-dedent-fix-missing-esm-type-definition
$ cd reproduction-dedent-fix-missing-esm-type-definition
$ npm i
$ npm run build

> app_name@0.0.0 build
> tsc -p tsconfig.build.json

src/index.ts:5:15 - error TS2349: This expression is not callable.
  Type 'typeof import("/Users/mizdra/src/github.com/mizdra/reproduction-dedent-fix-missing-esm-type-definition/node_modules/dedent/dist/dedent")' has no call signatures.

5   console.log(dedent`text`);
                ~~~~~~


Found 1 error in src/index.ts:5

src/index.ts:

import dedent from 'dedent';

export function run() {
  // eslint-disable-next-line no-console
  console.log(dedent`text`);
}

This problem can also be detected by publint.

Solution

To solve this problem, I added the ESM type definition file (./dist/dedent.d.mts).

I have also confirmed that this patch allows tsc to pass.

$ npm i -S ../dedent
$ npm run build

> app_name@0.0.0 build
> tsc -p tsconfig.build.json

$ echo $?
0

Copy link
Collaborator

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, thanks @mizdra!

@JoshuaKGoldberg JoshuaKGoldberg merged commit e184a9e into dmnd:main Jul 30, 2023
@JoshuaKGoldberg
Copy link
Collaborator

Published in dedent@1.4.0, thanks!

@mizdra mizdra deleted the fix-exports-type branch July 31, 2023 14:53
@mizdra
Copy link
Contributor Author

mizdra commented Jul 31, 2023

@JoshuaKGoldberg Thanks for the quick response! However, it seems that dedent.d.mts is not included in the published package.

Did you forget to yarn run build before publish?

@JoshuaKGoldberg
Copy link
Collaborator

Ah, no, it's missing in package.json files. Adding now.

@mizdra
Copy link
Contributor Author

mizdra commented Jul 31, 2023

Oh, I forgot to include it in files field of package.json. Sorry!

@JoshuaKGoldberg
Copy link
Collaborator

Funny how the little old things like that get in the way, right after figuring out the new ESM exports... Fixed in dedent@1.5.1 / https://github.com/dmnd/dedent/releases/tag/v1.5.1.

@mizdra
Copy link
Contributor Author

mizdra commented Jul 31, 2023

Has 1.5.1 already been released? It seems not to have arrived at npmjs.com yet.

https://www.npmjs.com/package/dedent

image

@JoshuaKGoldberg
Copy link
Collaborator

Hmm, try again? Might be a caching thing: https://www.npmjs.com/package/dedent/v/1.5.1

Screenshot of 1.5.1 published

(the publish took suspiciously long on my end...)

@mizdra
Copy link
Contributor Author

mizdra commented Jul 31, 2023

Successfully installed. I have confirmed that the problem with the type definition file has also been resolved.

Thank you!

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.

None yet

2 participants