question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't get type declarations to work in ES Module project

See original GitHub issue

I’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.

2022-11-30T22-21-54 Thanks in advance for any help with this.

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Comments:16 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
ganigeorgievcommented, Dec 6, 2022

The “fix” should be available with the v0.8.3 release.

1reaction
ganigeorgievcommented, Dec 6, 2022

I think I found the related TS issue - https://github.com/microsoft/TypeScript/issues/50762.

It seems that the problem is with how the exports is resolved and ts for some reason makes a guess where the declaration file is located instead of loading it directly from the types prop (either in the root level or as part of an exports block; the position of the types key also seems to matter).

I’ll reopen the issue and will update sometime later the file extension to generate it with .mts.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found