devrafalko / exact-math

exact-math solves the problem of floating point arithmetic operations precision.
https://devrafalko.github.io/exact-math/simulator
47 stars 6 forks source link

Formula Error when building for production #7

Closed Wyzix33 closed 5 years ago

Wyzix33 commented 5 years ago

Hi, I get this error when i try to execute a simple formula:

Uncaught Error: Invalid '(19/100)' expression. It contains illegal combination: '19/'.

this is the only line i use exact-math on this page:

let a= exactMath.formula('(1125.50*(19/100))+1125.50', { returnString: true});

This formula works in --mode=development but not in --mode=production.

I manage to make it work in production by importing from src like this:

import exactMath from 'exact-math/src/exact-math';

My setup: I'm using https://github.com/WeAreAthlon/frontend-webpack-boilerplate on Windows 10

Thanks

devrafalko commented 5 years ago

The problem is the TerserPlugin configuration in the webpack.config.js file. It minifies (mangles) the variables names and presumably it does not convert all of the quoted variables in the exact-math module, thus it causes some bugs. You can disable mangling in your webpack config file and it fixes the problem.

optimization: {
  minimizer: [
    new TerserPlugin({
      parallel: true,
      terserOptions: {
        mangle: false
      },
    }),
    new OptimizeCssAssetsPlugin({}),
  ],
},
Wyzix33 commented 5 years ago

Hi, it works now, but doing this also adds about 400kb on my final js files, so for now i will include it by src and will try to integrate exact-math tests into my tests to see if everything is OK. Thank you for your help and great job with the library.

devrafalko commented 5 years ago

Try to reinstall exact-math with the new @2.1.0 version. I've fixed the of-type dependency that compares constructors now rather than their names that are mangled, so it can be now minified with your initial TerserPlugin configuration. I've implemented the TerserPlugin to my webpack config and it seems to work with all tests passed

Wyzix33 commented 5 years ago

It works! Thanks