mathjs: ERROR TypeError: Cannot convert 2546 to type "undefined"; valid output types are number, BigNumber, Fraction
Hello, I’m trying to use the evaluate() method to do some math using a string in an Angular application. This is my method:
calculateMileageCharge() {
let formula = this.worksheet.mileageChargeRef;
formula = formula.replace('${firstMileage}', this.worksheet.firstMileage.toString();
formula = formula.replace('${purPrice}', this.mainForm.get('purPrice').value);
this.worksheet.mileageChargeRefCal = evaluate(formula);
}
The formula var works out to be: “2546 * (9988 / 120000)” but any formula (i.e. 2*3) throws the same error with the first number in the formula.
This all works fine while developing, but as soon as I use ng build --prod
i get the error in the title. Building without --prod works fine.
This is my package.json, in case it helps. The prod build uses the “build:prod” script:
{
"name": "bbms",
"version": "0.2.0",
"scripts": {
"ng": "ng",
"postinstall": "node version.js",
"start": "ng serve -c localapi",
"start:devapi": "ng serve -c devapi",
"start:localapi": "ng serve -c localapi",
"build": "ng build",
"build:prod": "npm version minor --no-git-tag-version && node version.js && ng build --prod --baseHref=/bbms/ --deploy-url=/bbms/resources/bbms/",
"build:prodMajor": "npm version major --no-git-tag-version && node version.js && ng build --prod --baseHref=/bbms/ --deploy-url=/bbms/resources/bbms/",
"build:prodPatch": "npm version patch --no-git-tag-version && node version.js && ng build --prod --baseHref=/bbms/ --deploy-url=/bbms/resources/bbms/",
"build:prodNoVer": "ng build --prod --baseHref=/bbms/ --deploy-url=/bbms/resources/bbms/",
"build:eclipse": "ng build --configuration=eclipse --output-path=../webapp/resources/bbms --baseHref=/bbms/ --deploy-url=/bbms/resources/bbms/",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/animations": "^7.2.2",
"@angular/cdk": "^7.2.2",
"@angular/common": "^7.2.10",
"@angular/compiler": "^7.2.10",
"@angular/core": "^7.2.10",
"@angular/flex-layout": "^7.0.0-beta.24",
"@angular/forms": "~7.2.2",
"@angular/material": "^7.2.2",
"@angular/platform-browser": "~7.2.2",
"@angular/platform-browser-dynamic": "~7.2.2",
"@angular/router": "~7.2.2",
"@fortawesome/angular-fontawesome": "^0.3.0",
"@fortawesome/fontawesome-svg-core": "^1.2.12",
"@fortawesome/free-solid-svg-icons": "^5.6.3",
"@types/mathjs": "^6.0.0",
"angular-file": "^1.2.2",
"angular-in-memory-web-api": "^0.8.0",
"core-js": "^2.5.4",
"fs-extra": "^8.1.0",
"google-libphonenumber": "^3.2.2",
"hammerjs": "^2.0.8",
"jquery": "^3.4.1",
"libphonenumber-js": "^1.7.15",
"mathjs": "^6.0.3",
"ng2-file-upload": "^1.3.0",
"ngx-infinite-scroll": "^7.1.0",
"ngx-spinner": "^7.1.4",
"rxjs": "~6.3.3",
"tslib": "^1.9.0",
"zone.js": "~0.8.26"
},
"devDependencies": {
"@angular-devkit/build-angular": "^0.12.4",
"@angular/cli": "^7.3.6",
"@angular/compiler-cli": "^7.2.10",
"@angular/language-service": "~7.2.2",
"@ryaneharris/bbms-schematics": "^0.1.1",
"@types/google-libphonenumber": "^7.4.17",
"@types/jasmine": "~3.3.8",
"@types/jasminewd2": "~2.0.3",
"@types/jquery": "^3.3.29",
"@types/node": "~10.12.18",
"codelyzer": "~4.5.0",
"jasmine-core": "~3.3.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~4.0.0",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.1",
"karma-jasmine": "~2.0.1",
"karma-jasmine-html-reporter": "^1.4.0",
"protractor": "~5.4.0",
"ts-node": "~8.0.1",
"tslint": "~5.12.1",
"typescript": "~3.2.4"
}
}
Let me know if you need more info.
Thanks!
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 3
- Comments: 24 (11 by maintainers)
The same issue here with angular. On localhost, before build it’s working, but after ng build --prod, I have the same error message. @Update - ShiftyMcCool I downgrade to 5.10.3 and @types to 5.0.1 and it’s working. Thank you.
Sure, I might need a couple days though, I’m on a tight deadline for this project and will be able to breathe pretty soon. I’ll post back with the URL when it’s ready.