Hi,
I am building a Meteor app, and I am using the jStat library. I have some weird trouble with imports, using Meteor 1.3.
When I use the import { jStat } from jStat
, my server test are passing and jStat is correctly loaded. But it does not work on the client side and on client test, jStat object is undefined.
When I use the import 'jStat'
syntax, that’s the opposite… jStat is undefined in my server test, but defined in my template and my client test.
I did install meteor-node-stubs
, it did not change anything.
I also tried import * as jStat from jStat
, but it only has the same effect than import jStat from 'jStat'
.
It seems to be an issue related to jStat itself, that has a weird loading behaviour (https://github.com/jstat/jstat#module-loaders).
Here are my files :
/imports/math/rates.js
import { jStat } from 'jStat';
/**
* Confidence interval calculation on proportions
* @return {[type]} [description]
*/
export const Rates = function(){
var self = this;
self.ualpha = function(alpha){
var mean = 0;
var std =1;
return jStat.normal.inv(1-alpha/2,0,1);
};
return self;
}();
/imports/math/rates.tests.js (the test file for rates.js)
import { Meteor } from 'meteor/meteor';
import { Template } from 'meteor/templating';
import { Events } from '/collections/events.js';
import { Stubs } from '/imports/testing/stubs.js';
import { TestHelpers } from '/imports/testing/helpers.js';
import { assert } from 'chai';
import { Rates } from '/imports/math/rates.js';
describe('Rates Helpers', () => {
beforeEach(()=>{
});
it("Should compute ualpha",()=>{
var eps = 10e-7;
assert.approximately(1.959964,Rates.ualpha(0.05),eps);
assert.approximately(1.644854, Rates.ualpha(0.1),eps);
assert.approximately(2.575829, Rates.ualpha(0.01),eps);
});
});
/client/rates/ui/pages/experiment.js (the template)
import { Template } from 'meteor/templating';
import { Rates } from '/imports/math/rates.js';
import 'meteor/manuel:viewmodel';
Template.rates_experiment.viewmodel({
alpha:0.01,
rate: 0.5,
precision: 0.01,
interval:'constant',
nIdeal : function(){
var self = this;
return Rates.nIdeal(self.rate, self.alpha, 'constant',self.precision);
}
});
I also posted my issue on stackoverflow here : http://stackoverflow.com/questions/37187233/npm-import-with-meteor-conflict-between-test-and-production
Did anybody have the same issue with imports ?