Being a newcomer to importing libraries into personal projects, I am attempting to import the mathjs library package for the first time.
().
However, I am running into the issue on my website where it says "math is undefined" when I try to use it.
You can see a photo of the error in the console log here
// This is an example from my JavaScript code where I try to utilize the library:
math.evaluate('12 / (2.3 + 0.7)');
This is a new experience for me and I might've missed a crucial step. What step could I be overlooking?
Here are the steps I have followed so far:
- Ran NPM install
npm install mathjs --save
- Confirmed the presence of the new dependency in package.json:
"dependencies": {
"mathjs": "^12.4.0"
}
- Even after trying these two methods separately, I still encounter the same error "math is undefined.":
<script src="math.js" type="text/javascript"></script>
<script src="math.min.js" type="text/javascript"></script>
- Substituting those with 'require' resulted in a different, fatal error:
const math = require('mathjs');
Fatal error: Constant expression contains invalid operations in C:\xampp\htdocs\GroceryListGenerator\Pages\index.php on line 3