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

SyntaxError: Unexpected token 'export' in Jest environment using mathjs/number #1766

Closed
kyoncy opened this issue Mar 11, 2020 · 4 comments
Closed

Comments

@kyoncy
Copy link

kyoncy commented Mar 11, 2020

Error Description

I use mathjs@6.6.1 in my application

import { median, mode } from 'mathjs/number';

When execute Jest test, this error was displayed.

  ● Test suite failed to run

    /path/to/project/node_modules/mathjs/number.js:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){export * from './main/esm/number' // eslint-disable-line
                                                                                             ^^^^^^

    SyntaxError: Unexpected token 'export'

Suggestion

In mathjs/index.js using module.exports

module.exports = require('./lib/entry/mainAny')

But mathjs/number.js using export * from '' different from mathjs/index.js

export * from './main/esm/number' // eslint-disable-line

So, I change the mathjs/number.js, Jest test was passed.

- export * from './main/esm/number' // eslint-disable-line
+ module.exports = require('./lib/entry/mainNumber') 
@josdejong
Copy link
Owner

Thanks for reporting, this is a good point and is currently inconsistent. We should be careful to change this, that may break existing usage.

for the main library mathjs, we have an automatic switch in package.json to select either commonjs or ESM:

{
  "main": "main/es5",
  "module": "main/esm"
}

I'm not sure if it is possible to have this switch working for mathjs/number too - right now this only points to the ESM version.

Any ideas?

@josdejong
Copy link
Owner

btw you can always use the right import by choosing from:

  • mathjs/main/es5
  • mathjs/main/es5/number
  • mathjs/main/esm
  • mathjs/main/esm/number

@josdejong
Copy link
Owner

Anyone able to figure out the consequences and think through a solution? Help would be very welcome.

@GreenImp
Copy link
Contributor

I mentioned this briefly on #1928 but this problem may be solvable using Subpath Exports. I've not used them before, but the documentation looks promising.

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

Successfully merging a pull request may close this issue.

3 participants