-
Notifications
You must be signed in to change notification settings - Fork 480
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeError: __WEBPACK_IMPORTED_MODULE_4_decimal_js__ is not a constructor #59
Comments
Same here |
I had something similar, had to change an import Have you tried the following? import { Decimal } from 'decimal.js'; |
Same problem here |
Use
Compile and execute
(typescript v2.4.1, node v8.1.3) It works fine for me. #49 is related to this issue. I also think the typings need updating as discussed at this stackoverflow question regarding bignumber.js (related issue). |
I'm using angular-cli (it uses webpack do run) |
I have no experience of using Angular CLI. Does the code work if you change
to
|
my-app.zip I create a simple example of the problem (the zip attached). i use the angular-cli, create a new project, install the dependencies, change the constructor to log the decimal, add the decimal.js/decimal.js as dependency in .angular-cli.json and try to use the decimal.js. to test is just unzip an run:
Thank you @MikeMcl for your help Edit: Forgot the attachement Edit2: If you change the app.component.ts and remove the import this example works. Looks like the import its all done by the configurations of the angular-cli (src/tsconfig.app.json and .angular-cli.json). One note, the type is decimal.Decimal and to access the constructor you shold use new Decimal(10.21). |
Hello together, i tried to follow your instructions, but couldn't get it working in angular-cli v.1.1.1 |
@jblankenhorn to run
I'm using angular-cli 1.2 |
@eloyleonardo i am not sure if this is the preferred way ... as far as I See, you are loading the decimal.js as a global script here ... and not via an import statement ... |
I have a similar issue to this. Everything works fine in a node environment where decimal.js (the file) is loaded. The problem is that webpack loads decimal.es6.js (the file) and that has a different export format (it uses default). Note that webpack picks up on the With that kind of export, webpack appears to think that everything will import it a specific way too (accounting for defaults). If you are using node style imports ( There will be something you can do with webpack to use the non ES6 version of decimal.js (I'm not overly familiar with webpack to suggest anything). Otherwise, you will have to update all your imports to be ES6 style too. Or just do as @josdejong said and change your require to be |
same problem. any workaround will be appreciated |
Hopefully, this issue is fixed in v7.2.4. |
I have code like this:
It works with 7.1.2 and still fails with 7.2.4. It's an Angular CLI app (WebPack vesion 3.4.1).
And at runtime I get:
|
Following Colin Bradley's comment above, does your code work if |
Yes, removing that line works. The compile and runtime messages disappear. |
Okay, thanks. And using
works fine also does it, even with the Also, you could try adding the following to your webpack options object resolve: {
mainFields: ["main", "module"]
} |
Using However, there is something I don't understand (I'm a Java programmer, new to JS...). When creating a variable I have to change But when declaring a variable type I have to use I'm using Angular CLI, I don't know if there is a way of configuring webpack as it's managed internally by the tool. |
The |
I have |
I'm also unable to get this to work with webpack, any ideas? |
Create and use your own // @flow
import toFormat from "toformat";
const RawDecimal = require("decimal.js/decimal.js");
export const Decimal = toFormat(RawDecimal);
export default Decimal; Usage: import Decimal from "./decimal.js"
const x = new Decimal(1); Worked for me. |
i use this way to fix: |
A TypeScript delaration file is now included in this repository. The typings at DefinitelyTyped are outdated, so |
be careful using: |
Hi,
getting the following error,
TypeError: __WEBPACK_IMPORTED_MODULE_4_decimal_js__ is not a constructor
I have installed,
here is what I have done to get this error
using,
with "typescript": "~2.3.4"
The text was updated successfully, but these errors were encountered: