Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: math.import is not a function #1997

Closed
rev111 opened this issue Oct 15, 2020 · 2 comments
Closed

Error: math.import is not a function #1997

rev111 opened this issue Oct 15, 2020 · 2 comments
Labels

Comments

@rev111
Copy link

rev111 commented Oct 15, 2020

Hello,
I'm using

  • node 14.5.0
  • mathjs 7.5.1, installed 7.1.0 with npm and updated through package.json

in a node project with ES6 imports. I import mathjs like this:
import math from 'mathjs';
So far I had no issues. evaluate() and parse() worked. Now I would like to use import for a custom function:

math.import({
            myvalue2: 42
}

and get the error:
TypeError: math.import is not a function

I think, but I am not sure that this is related to pull request #1941.
That is because I started learning node with this project and used ES6 from the beginning. It's still kind of a mystery to me what i.e. gulp or rollup does.

I tried several variations of
import { all } from 'mathjs';
but that fails immediately with

import { all } from 'mathjs';
         ^^^
SyntaxError: The requested module 'mathjs' is expected to be of type CommonJS, which does not support named exports. CommonJS modules can be imported by importing the default export.

My question is, am I doing something wrong? Is there something I should do differently (preferrably without recompiling the source because I don't know how to do that)?
Thank you, rev111

@rev111
Copy link
Author

rev111 commented Oct 17, 2020

I solved this with a different import:
import math from './node_modules/mathjs/dist/math.js';
seems to work fine.

@rev111 rev111 closed this as completed Oct 17, 2020
@josdejong
Copy link
Owner

👍

I hope indeed that #1941 will solve many of those issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants