-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Load mathjs in a browser module (ES import) #1841
Comments
this is not worked for me when import mathjs in vite |
I have read https://nodejs.org/api/esm.html#esm_dual_commonjs_es_module_packages a couple of times to try and work out what we should do. Not yet grokked it completely though. |
@josdejong what is your take on the duel package hazard. Does it apply to mathjs? I cannot remember if we still have global state? |
It's quite complicated :S mathjs has no global state, you have to create your own mathjs instance with for example |
I think you're correct about the lack of file extension; browser environments expect the full path and filename. |
I found a related issue at i18next/i18next#1667 (comment). Since math uses babel to compile ESM through gulp, I think this will be helpful. (Also, the error message explicitly mentioned that it failed to resolve |
Thanks Hanchai for your input, an ESM bundle would indeed solve that because there are no imports without I had anther look to see if a non-bundle ESM code could work:
So all in all, I think generating a single ESM bundle makes a lot of sense (it is also way faster then loading many tiny files). We should make sure though that tree-shaking still works on this bundle. Anyone interested trying this out? |
Currently it looks like it's not possible to use mathjs in a browser module like:
I think the existing bundles in
dist
do not have the right exports to be consumed as an ES module.What should work (but doesn't) is loading like:
I think the reason is that many import paths in the code are missing the explicit "*.js" extension, which is the normal way to go in nodejs and webpack environments, but not in browser ES environments which require a real path to a file.
The text was updated successfully, but these errors were encountered: