primer / octicons

A scalable set of icons handcrafted with <3 by GitHub
https://primer.style/foundations/icons
MIT License
8.34k stars 828 forks source link

[Bug] Esm requires file extension in d.ts files. #1018

Closed ankoh closed 7 months ago

ankoh commented 7 months ago

Typescript projects using the moduleResolution NodeNext or node16 cannot consume @primer/octicons-react 19.9.0 (and transitively @primer/react36.13.0, regressing from 36.12.0) since the icons type definition is not imported with a file extension.

The import will just fail and, when peeking into the index.d.mts, you'll find the error:

relative import paths need explicit file extensions in ecmascript imports

Patch that worked for me on dist:

diff --git a/dist/index.d.mts b/dist/index.d.mts
index acfe71a1ce71b4764c3d155334b3bbc2830ea5d0..8539c08534ff1732a8f80c3ba850dfd6cc7f4ac8 100644
--- a/dist/index.d.mts
+++ b/dist/index.d.mts
@@ -2,7 +2,7 @@
 import * as React from 'react'

 // eslint-disable-next-line prettier/prettier
-import { Icon } from './icons'
+import { Icon } from './icons.js'

 type Size = 'small' | 'medium' | 'large'

@@ -20,4 +20,4 @@ export interface OcticonProps {
   verticalAlign?: 'middle' | 'text-bottom' | 'text-top' | 'top' | 'unset'
 }

-export * from './icons'
+export * from './icons.js'

I guess it's just https://github.com/primer/octicons/blob/main/lib/octicons_react/src/index.d.ts

ankoh commented 7 months ago

@joshblack since this was introduced with #1008

joshblack commented 7 months ago

Thanks for taking the time to make this issue @ankoh! Really appreciate it. Opened a PR over at: https://github.com/primer/octicons/pull/1020 to (hopefully) address this 👍