I use [email protected] 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'
In mathjs/index.js using module.exports
https://github.com/josdejong/mathjs/blob/86606dc7bedf742e7d6af1423a99552ec0711139/index.js#L5
But mathjs/number.js using export * from '' different from mathjs/index.js
https://github.com/josdejong/mathjs/blob/86606dc7bedf742e7d6af1423a99552ec0711139/number.js#L1
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')
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?
btw you can always use the right import by choosing from:
mathjs/main/es5mathjs/main/es5/numbermathjs/main/esmmathjs/main/esm/numberAnyone able to figure out the consequences and think through a solution? Help would be very welcome.
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.