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.

TypeScript typing problem - numbro.d.ts should not use "export default"

See original GitHub issue

The TypeScript typing file for numbro has recently been changed as follows between versions 2.1.0 and 2.1.1:

-export = numbro;
+export default numbro;

(Related issue: #352, related PR: #363)

This causes problems if Numbro is being used in a TypeScript project where tsconfig.json specifies module: "commonjs" and target: "es5". Since the typing file declares that numbro has a default export, TS only accepts the following syntax to import the entire module:

import numbro from "numbro";


However, this transpiles down to the following in ES5:

var numbro_1 = require("numbro");


which is incorrect because the JS code of numbro does not have a property named default - the module exports the entire numbro function as the module-level export instead. I believe that the typing file should revert to export = numbro to reflect this, or the module itself should include exports.default = numbro to provide a default export.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:16
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

isidorospcommented, Apr 2, 2020

I’m still getting this in 2.2.0 with the following tsconfig: "module": "commonjs", "target": "es2019", the following import statement: import numbro from 'numbro'; and the following usage: numbro(value).format({ thousandSeparated: true, mantissa: 2 }); the following error occurs: numbro_1.default is not a function TypeError: numbro_1.default is not a function

EDIT: @BenjaminVanRyseghem Sorry for the @ but just checking if you had a chance to see the above as the issue was closed when I commented.

ntamascommented, Oct 15, 2019

@BenjaminVanRyseghem this is still an issue, as exemplified by #435; the changes provided in #430 does not address the original problem reported here.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Documentation - Modules .d.ts - TypeScript
The types which are exported can then be re-used by consumers of the modules using either import or import type in TypeScript code...
Read more >
About "*.d.ts" in TypeScript - Stack Overflow
The "d.ts" file is used to provide typescript type information about an API that's written in JavaScript. The idea is that you're using...
Read more >
TypeScript errors and how to fix them
Fixed Code ✔️. If you want to export a constant from a definition file ( d.ts ), then you have to use the...
Read more >
typescript-cheatsheet - GitHub Pages
Default exports are marked with the keyword default; and there can only be one default export per module. default exports are imported using...
Read more >
Announcing TypeScript 4.7 - Microsoft Developer Blogs
TypeScript can use this information to help you avoid about mistakes ... CommonJS modules as if they were ES modules with a default...
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 Post

No results found

github_iconTop Related Hashnode Post

No results found