silentmatt / expr-eval

Mathematical expression evaluator in JavaScript
http://silentmatt.com/javascript-expression-evaluator/
MIT License
1.19k stars 239 forks source link

export 'Parser' was not found in 'expr-eval' #212

Closed rnadler closed 4 years ago

rnadler commented 4 years ago

I have a Typescript project with:

import {Parser} from 'expr-eval';

The above works fine with 1.2.3 but 2.0.1 compilation fails with:

export 'Parser' was not found in 'expr-eval'

Versions: typescript: 3.5.3 webpack: 4.40.2

I'm probably missing something simple, but I can't seem to find a solution. Thanks!

Cactusbone commented 4 years ago

I'm not using Typescript so I cannot be sure this works, but assuming it follows es modules:

index.js file define:

export default {
  Parser: Parser,
  Expression: Expression
};

Which means you cannot import Parser directly (using es module), you need to use an intermediate variable:

import ExprEval from 'expr-eval';
const {Parser} = ExprEval;

To fix it index.js should be defined without specifying default (along with current default to avoid compatibility issues)

export {
  Parser: Parser,
  Expression: Expression
};
silentmatt commented 4 years ago

Thanks for reporting this. I'm not sure what my original reason for using export default was, but I added exports for Parser and Expression, which I believe (like @Cactusbone mentioned) should fix the issue. Can you try this with version 2.0.2, and let me know how it goes?

rnadler commented 4 years ago

I can confirm that 2.0.2 resolves export issue. Thanks!

silentmatt commented 4 years ago

@rnadler Great, thank you!