Type definition generated for CommonJS output using module.exports =
is not usable
#51
Labels
bug
Something isn't working
module.exports =
is not usable
#51
Problem
The type definition file generated for CommonJS output using
module.exports =
syntax is not consumable by TS projects withoutesModuleInterop
enabled or JS projects with type checking or editors with support for type hints on JavaScript files.For example, given this TypeScript input:
The JavaScript file generated when using
pkgroll
v2.0.1 will be:And this will be created along with the following type definition:
However, when a project using CommonJS modules consumes the compiled files like so:
Then they will receive the following error when running a type check on their code or attempting to use type hints in their editor because these are expecting the implementor to reference a property named "default":
Because there's no equivalent of
module.exports =
with ESM the Rollup documentation suggests always using named export mode to avoid creating two different interfaces:So whilst neither of these may be ideal I understand there are two potential solutions for this problem:
export =
syntax.named
export mode to outputexports.default =
(p.s. apart from this hiccup, the project has been A+, thank you)
Expected behavior
The module imported using require should have the correct type definition applied and editor type hints enabled. The following type definition would work:
Alternatively, the following generated JS would work:
Minimal reproduction URL
https://gist.github.com/i-like-robots/29b8662210f6898626f40d49e8e39e68
Version
v2.0.1
Node.js version
v18.18
Package manager
npm
Operating system
macOS
Contributions
The text was updated successfully, but these errors were encountered: