question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't import jStat in Meteor

See original GitHub issue

Hi,

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:open
  • Created 7 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
trevnorriscommented, Jun 8, 2016

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.

0reactions
eric-burelcommented, May 17, 2016

Here are the step to reproduce :

# install meteor and create an app
curl https://install.meteor.com/ | sh
meteor create jstat-sample
cd jstat-sample
# install jstat
meteor npm install --save jStat
mkdir imports

So, you should have three folder, client,server and imports. Here is a sample file importing jStat that should be imported both on the server and the client.

imports/stat.js

import 'jStat';

export const Stat = function(){
        this.ualpha = function(alpha){
                return jStat.normal.inv(1-alpha/2,0,1);
        }
        return this;
}();

Then, here are basic main.js and main.html, with an helper.

client/main.html (most of the file is auto-generated by meteor, I simply added {{ualpha}} to call the helper)

<head>
  <title>simple</title>
</head>

<body>
  <h1>Welcome to Meteor!</h1>
  {{> hello}}
  {{> info}}
</body>

<template name="hello">
  <button>Click Me</button>
  <p>You've pressed the button {{counter}} times.</p>
  <p>{{ ualpha }} </p>
</template>

<template name="info">
  <h2>Learn Meteor!</h2>
  <ul>
    <li><a href="https://www.meteor.com/try">Do the Tutorial</a></li>
    <li><a href="http://guide.meteor.com">Follow the Guide</a></li>
    <li><a href="https://docs.meteor.com">Read the Docs</a></li>
    <li><a href="https://forums.meteor.com">Discussions</a></li>
  </ul>
</template>

client/main.js (same, I simply added an ualpha helper that calls Stat.ualpha)

import { Template } from 'meteor/templating';
import { ReactiveVar } from 'meteor/reactive-var';
import { Stat } from '/imports/stat.js';

import './main.html';

Template.hello.onCreated(function helloOnCreated() {
  // counter starts at 0
  this.counter = new ReactiveVar(0);
});

Template.hello.helpers({
  counter() {
    return Template.instance().counter.get();
  },
   ualpha(){
           return Stat.ualpha(0.01);
    }
});

Template.hello.events({
  'click button'(event, instance) {
    // increment the counter when button is clicked
    instance.counter.set(instance.counter.get() + 1);
  },
});

So far, everything should be working when you run meteor run and open localhost:3000.

Now, here is the code on the server side : server/main.js

import { Meteor } from 'meteor/meteor';
import { Stat } from '/imports/stat.js';

Meteor.startup(() => {
  // code to run on server at startup
  console.log("u(0.01) : " + Stat.ualpha(0.01));
});

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 (like import { 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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can't import a module in MeteorJS - Stack Overflow
1 Answer 1 ... The error message is due to your file in "shared > methods.js" attempted to be compiled by Meteor build...
Read more >
jStat - npm
Start using jStat in your project by running `npm i jStat`. There are 39 other projects in the npm registry using jStat.
Read more >
Import from /client to server - help - Meteor forums
When I import code from the imports folder, it works : import test from '/imports/test.js';. But when I add the client folder :...
Read more >
Untitled
Ponglang monster, Jstat gcutil option, Nekpijn oefeningen? ... Good boys blondie lyrics, Disegni realistici con photoshop, Live meteor shower feed uk!
Read more >
sdkman/user-issues - Gitter
hello , when I use ' sdk install groovy',I got an error 'mv: cannot stat '/root/.sdkman/tmp/FfWqe2OMFjAqJdNptwRBS1Zy3PJUYJQS.bin': No such file or directory ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found