Can't get type declarations to work in ES Module project
See original GitHub issueI’ve read a bunch of other issues which gave me the impression that with the "type": "module" setup, it should work out of the box, but I’m clearly doing something else wrong.
The warning on the import statement is:
Could not find a declaration file for module 'pocketbase'. 's:/New folder (5)/pocketbase/node_modules/pocketbase/dist/pocketbase.es.mjs' implicitly has an 'any' type.
Thanks in advance for any help with this.
Issue Analytics
- State:
- Created 10 months ago
- Comments:16 (9 by maintainers)
Top Results From Across the Web
Type declaration file doesn't work with commonjs module syntax
Today I was writing a type declaration file for a JavaScript file but despite my hours of trying I couldn't make it work...
Read more >ES modules not supported · Issue #1291 · vercel/pkg - GitHub
Setting the targets doesn't change anything, I've tried different targets and even running on different platforms... It does however run if I don't...
Read more >Documentation - ECMAScript Modules in Node.js - TypeScript
This code works in CommonJS modules, but will fail in ES modules because relative import paths need to use extensions. As a result,...
Read more >Using ES modules in Node.js - LogRocket Blog
To be able to load an ES module, we need to set “type”: “module” in this file or, as an alternative, we can...
Read more >Node Modules at War: Why CommonJS and ES ... - Code Red
Put the ESM wrapper in an esm subdirectory, alongside a one-line package.json file that says {"type": "module"} . (You could rename your wrapper ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

The “fix” should be available with the v0.8.3 release.
I think I found the related TS issue - https://github.com/microsoft/TypeScript/issues/50762.
It seems that the problem is with how the
exportsis resolved and ts for some reason makes a guess where the declaration file is located instead of loading it directly from thetypesprop (either in the root level or as part of anexportsblock; the position of thetypeskey also seems to matter).I’ll reopen the issue and will update sometime later the file extension to generate it with
.mts.