Use epicenter lib as node modules for local interface build

This issue is related to previous topic and still not resolved. I spent too much time on this and really hope it can resolved.

Goal: use epicenter lib CommonJS style. Use npm install epicenter module so that latter I can use require to add dependency to it. Currently not working has to put script tag in html file as workaround. It work around does not work well for server side though. Hope to make it work right.

I tried different things including everything Naren has suggested. None of them work, here is closest thing I can get.

  1. install epicenter using command npm install git+https://github.com/forio/epicenter-js-libs --save
    It outputs Epicenter-JS-Libs@1.5.0 node_modules/Epicenter-JS-Libs. However I don’t see lib dir under it as other modules does.
  2. in my source code
    `
    var F = {
    util: {},
    factory: {},
    transport: {},
    store: {},
    service: {},
    manager: {
    strategy: {}
    },

};

F.service.Data = require(‘Epicenter-JS-Libs/src/service/data-api-service’);
`
Notice I have to put ‘src’ in the path since no lib is present.

  1. Result: Build error AuthManager.prototype = $.extend(AuthManager.prototype, { ^ ReferenceError: $ is not defined Yes, jQuery is not there. somehow npm doesn’t think it depends on jQuery.

Please help.

Hi Jay,

As you pointed out, EpicenterJS isn’t set-up to be used as a node package; it is however set-up as a bower package, and that’s what we use internally so we could offer more guidance there. We’ll take a look at commonjs support in a release early-mid December (or I’m happy to accept a pull-request if you know what needs to be changed).

I want to point out though that making it require-able won’t automatically make this work within Node. We use jquery for ajax, which won’t directly translate to node. The ‘framework’ is there, but implementation isn’t there yet (i.e., the libraries are setup to use https://github.com/forio/epicenter-js-libs/blob/master/src/transport/node-http-transport.js as needed, but of course that file is blank now).

I’m curious what your use-case is for using this from node - we’ve done dozens of simulations without needing this, so maybe we can offer alternative suggestions for implementation.

Hi Naren,

Thank you for pointing out it’s two things. One is use npm for packing or at least commonJS compatible for local development. The other is to make epicenter.js more isomorphic.

The first is really needed now, I am using script src tag in html as workaround and I will wait for a solution.

The second, making epicenter.js working both server side and client side will be really nice. That’s the trend of client apps. By making epicenter.js isomorphic gives front end design more freedom.

Jay

Hi Jay, The master branch should have a (potential) npm compatible version - can you try it out? We’ll need to qa it of course, but if this works for you I can make sure this goes out in the next release next week.

jQuery will still likely be a problem though – it’s listed as a dependency in package.json but throughout the libraries the code assumes $ is present in the global namespace; i.e., we don’t explicitly do var $ = require('jquery') anywhere. This is because we want users to use jquery from a cdn, and not have to bundle jquery within epicenter.js (which it will be with our current build process which bundles everything "require"d)

Changing this will be nice, but that will push the eta back to the ‘mid-december’ timeline I mentioned in the previous post.

Either way, check out the latest from master and let us know if that works for you, and if not we’ll keep this open and update when the bigger changes are done.

Hi Naren,

You are right. It’s not working because of “ReferenceError: $ is not defined”. I have jQuery installed with npm, but that doesn’t help because as you pointed out epicenter expect $ from CDN. So seems the only way to make it work now is still with the script src tag workaround.

BTW, npm install git+https://github.com/forio/epicenter-js-libs --save works OK for epicenter. The issue is in how it reference jQuery.

Jay