Can't import jStat in Meteor
See original GitHub issueHi,
I am using Meteor, and I am not able to import jStat correctly. It either does work on server or on client, but never on both. I understood that it is because jStat export policies being different on client and on server, and therefore require a different import
call for each case.
However, I’d like to build a class that both work on a Node.js server and on the client, as it is very low level (confidence interval computation) and will be needed on both.
Here is a link to the corresponding Stack Overflow question with the code and more details.
Do you have an idea how I can import jStat correctly in my file ? Of course if (Meteor.isServer){...}
does not work, as the import must be at the beggining of JavaScript file and therefore can not be included in a branch.
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (3 by maintainers)
Think I may know what’s going on. The export method was abusing an old trick for node’s
module.exports
that should have also exported to global in the client side. Seems that’s not working any more. I’ll take a look into it.Here are the step to reproduce :
So, you should have three folder,
client
,server
andimports
. Here is a sample file importingjStat
that should be imported both on the server and the client.imports/stat.js
Then, here are basic
main.js
andmain.html
, with an helper.client/main.html (most of the file is auto-generated by meteor, I simply added
{{ualpha}}
to call the helper)client/main.js (same, I simply added an
ualpha
helper that callsStat.ualpha
)So far, everything should be working when you run
meteor run
and openlocalhost:3000
.Now, here is the code on the server side : server/main.js
This code will fail, as the naive
import 'jStat'
does only work on client. I tried a lot of strategies, some work only the server (likeimport { jStat } from jStat
), some only on the client.The snippet I have put in my last comment seems close to work, as it does work on the server and defines some kind of constructor on the client, but still is not the answer.