1

I am using Math.js to parse and evaluate a mathematical expression, and am following the example at https://mathjs.org/docs/custom_bundling.html#numbers-only as I only need basic number support. "mathjs": "^8.1.1", is listed in my package.json dependencies.

When I run the example code below, I get Module not found: Error: Can't resolve 'mathjs/number':

// use light-weight, numbers only implementations of functions
import { create, all } from 'mathjs/number'

const math = create(all)
Erich
  • 2,408
  • 18
  • 40

1 Answers1

1

Looks like maybe the documentation hasn't caught up. I was able to get this working by changing the line

import { create, all } from 'mathjs/number';

to

import { create, all } from 'mathjs/lib/esm/number';
Erich
  • 2,408
  • 18
  • 40
  • Does this still work for you? It doesn't for me. (And I have the same initial issue that you had) – Fly Jul 13 '21 at 19:57
  • Essentially yes, we still use `^8.1.1` but now import individual dependencies. `import { create, evaluateDependencies, addDependencies, subtractDependencies, multiplyDependencies, divideDependencies, powDependencies, /* ... */ } from 'mathjs/lib/esm/number';`. Then we do `const math = create({ addDependencies, subtractDependencies, multiplyDependencies, divideDependencies, powDependencies, /* ... */ });` – Erich Jul 14 '21 at 14:05
  • 1
    Thanks for answering. Unfortunately, neither works for me - I can't import from anything other than just straight-up "mathjs". You're not using TypeScript, by any chance? I'm suspecting the issue I have is arising from bad types linking or something. – Fly Jul 14 '21 at 20:45
  • Nope, vanilla JS – Erich Jul 15 '21 at 14:16