1

I am trying to use decimal.js with Typescript on the client side of a simple app that was booted with create-react-app - Typescript 2.8.1.

But even for a simple declaration of a = new Decimal(1) I'm just getting an error:

TypeError: __WEBPACK_IMPORTED_MODULE_0 default.a is not a constructor

I can't figure out what's exactly the problem. Nothing useful on Google.

JJJ
  • 32,902
  • 20
  • 89
  • 102
Neo
  • 11
  • 5
  • 1
    You need to show how you import `Decimal`. – JJJ Apr 22 '18 at 14:31
  • I tried - import { Decimal } from 'decimal.js'; import Decimal from 'decimal.js'; const decimal = require('decimal.js'). – Neo Apr 22 '18 at 14:35
  • 1
    Please show us the complete file. – Daniel Apr 22 '18 at 18:16
  • The code works without the the decimal. It's a simple react app that was created using create-react-app script. The app just contains render() { const a = new Decimal(1); return (
    a
    ) }.
    – Neo Apr 22 '18 at 23:10

1 Answers1

1

You have to import as decimal.js/decimal.