mathjs icon indicating copy to clipboard operation
mathjs copied to clipboard

React Native + Typescript Error: undefined is not an object (evaluating '_mathjs.default.derivative')

Open Sheharyar566 opened this issue 4 years ago • 6 comments

I'm trying to use the package in react native, and as a test i wrote this equation and used derivative, but i'm getting this error:

undefined is not an object (evaluating '_mathjs.default.derivative')

I tried using the library as

import * as math from 'mathjs/lib/browser/math';

but with this, the typings don't work...

Is there a workaround that lets me deal with this issue while being able to use typescript?

Sheharyar566 avatar Jun 24 '21 17:06 Sheharyar566

have you tried

import * as math from 'mathjs'

?

josdejong avatar Jun 26 '21 09:06 josdejong

yup... i did... but I get error as undefined is not an object... so, am I stuck with the lib as "mathjs/dist/math"?

It's a totally fresh react native project with typescript

Sheharyar566 avatar Jun 26 '21 16:06 Sheharyar566

Hey @Sheharyar566, I am sorry to hear mathjs doesn't work for you. However I'm struggling to reproduce the issue – I've tried creating a prototype in Expo and it works just fine: https://snack.expo.io/BLtpfslkT Have you used different NPM packages with your project (apart from React and React Native), so that we could be sure your bunlder works ok?

cshaa avatar Jun 26 '21 20:06 cshaa

ah yup.... here's my package.json deps


  "dependencies": {
    "mathjs": "^9.4.3",
    "react": "17.0.1",
    "react-native": "0.64.1",
    "react-native-math-view": "^3.9.3",
    "react-native-vector-icons": "^8.1.0"
  },
  "devDependencies": {
    "@babel/core": "^7.12.9",
    "@babel/runtime": "^7.12.5",
    "@react-native-community/eslint-config": "^2.0.0",
    "@types/jest": "^26.0.23",
    "@types/react-native": "^0.64.5",
    "@types/react-native-vector-icons": "^6.4.7",
    "@types/react-test-renderer": "^16.9.2",
    "babel-jest": "^26.6.3",
    "eslint": "^7.14.0",
    "jest": "^26.6.3",
    "metro-react-native-babel-preset": "^0.64.0",
    "react-test-renderer": "17.0.1",
    "typescript": "^3.8.3"
  },

i did try using mathjs in a totally new project too (a few days ago) but it gave error there too...

Sheharyar566 avatar Jun 27 '21 03:06 Sheharyar566

I'm having the same issue, but with fractions, I tried to rebuild the app with run-android but it didn't work neither.

Did you fix it? If so, do you remember anything useful?

ghost avatar Jan 25 '22 15:01 ghost

Okay. I solved mine, I don't know if works for you.

I was using import mathjs from 'mathjs'; but seems like just importing thing by thing makes it work. This is import {fraction} from 'mathjs'

I'm not using typescript, tho.

ghost avatar Jan 25 '22 16:01 ghost

Since it seems that a viable solution was found and as this issue is rather old, closing.

gwhitney avatar Oct 03 '23 03:10 gwhitney