Skip to content

fix: fix missing ESM type definition file - #67

Merged
JoshuaKGoldberg merged 1 commit into
dmnd:mainfrom
mizdra:fix-exports-type
Jul 30, 2023
Merged

JoshuaKGoldberg merged 1 commit into
dmnd:mainfrom
mizdra:fix-exports-type

Conversation

@mizdra

@mizdra mizdra commented Jul 30, 2023

Copy link
Copy Markdown
Contributor

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

> [email protected] 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

> [email protected] build
> tsc -p tsconfig.build.json

$ echo $?
0

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Copy link
Copy Markdown
Collaborator

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
Copy Markdown
Collaborator

Published in [email protected], thanks!

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

mizdra commented Jul 31, 2023

Copy link
Copy Markdown
Contributor Author

@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
Copy Markdown
Collaborator

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

@mizdra

mizdra commented Jul 31, 2023

Copy link
Copy Markdown
Contributor Author

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

@JoshuaKGoldberg

Copy link
Copy Markdown
Collaborator

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

@mizdra

mizdra commented Jul 31, 2023

Copy link
Copy Markdown
Contributor Author

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
Copy Markdown
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

mizdra commented Jul 31, 2023

Copy link
Copy Markdown
Contributor Author

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.

2 participants