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

Type error: Could not find a declaration file for module 'country-flag-emoji-polyfill' #8

Closed
pete-willard opened this issue Sep 17, 2023 · 6 comments · Fixed by #13
Closed

Comments

@pete-willard
Copy link

Hi Egbert! I switched the moduleResolution flag in tsconfig from node to bundler and I'm getting the following error:

Type error: Could not find a declaration file for module 'country-flag-emoji-polyfill'. '(...)/node_modules/.pnpm/country-flag-emoji-polyfill@0.1.4/node_modules/country-flag-emoji-polyfill/dist/index.modern.js' implicitly has an 'any' type. There are types at '(...)/node_modules/country-flag-emoji-polyfill/dist/index.d.ts', but this result could not be resolved when respecting package.json "exports". The 'country-flag-emoji-polyfill' library may need to update its package.json or typings.

@eteeselink
Copy link
Contributor

Could you try to debug it? Eg edit the package.json (right there in your node_modules/country-flag-emoji-polyfill) until it works?

And does it then still work when you change moduleResolution back to node?

Full disclosure, I’m no npm packaging guru so I would appreciate any help I can get

@pete-willard
Copy link
Author

pete-willard commented Sep 17, 2023

Neither am I 😅 I know it (npm packaging) can be a nightmare to get right though. Anyway, the error does go away when I get back to node. I'll fiddle around some more tomorrow. I'll get back to you if I find out something.

Some quick google results:

@pete-willard
Copy link
Author

pete-willard commented Sep 18, 2023

Ok, I got it to work. Here's what I did:

  • changed index.module.js extension to .mjs
  • created index.d.mts and copied the types from index.d.ts there (a reexport would also work I think)
  • added an exports section to the polyfill's package.json:
"exports": {
    ".": {
      "import": {
        "types": "./dist/index.d.mts", // put types first
        "default": "./dist/index.module.mjs"
      },
      "require": {
        "types": "./dist/index.d.ts",
        "default": "./dist/index.cjs"
      }
    }
  },
  • updated "module": "./dist/index.module.mjs" to point to the .mjs
  • added "index.d.mts" to files array

I'm not completely sure if all of these steps are necessary/correct, so take that as you will.

Some extra reading:

Hope this helps!

@juanparati
Copy link

I am also facing this issue using bundler as module resolution.

@eteeselink
Copy link
Contributor

I'm not sure how to solve this and I would appreciate PRs.

Thing is, @pete-willard's suggestions look nice but I worry that what fixed it for him may break things for others (including ourselves). Eg the nonstandard file extensions (or at least I'm not even sure how standard they are, just, it's Node-specific maybe?) Stuff like that. I haven't yet found a comprehensive guide about best practices for this stuff, ie how to package a library such that it works in all common bundlers, compilers and toolchains, and I'd appreciate some help.

Unfortunately I do not currently have the time to get to the bottom of this myself (eg try all popular bundlers with all popular settings and mess around until it works everywhere - that's a big project for a small polyfill).

@eteeselink
Copy link
Contributor

I'm closing this issue for lack of responses. I'm eager to address this but I'm not sure how and I currently lack the time to dive deep enough. Anyone, feel free to reopen if you run into this and/or know a robust solution!

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 a pull request may close this issue.

3 participants