Cannot use local epicenter-ja-libs for local development build

[current status]
I cannot get webpack build correctly with epicenter-js-libs. I manually put "epicenter-js-libs": "https://github.com/forio/epicenter-js-libs.git", in package.json file. run npm install. use require('Epicenter-JS-Libs')(ant other path variants). Does not compile, telling me epicenter-js-libs module not found.
[/current status]

It will be much more convenient if forio has npm package for APIs.

I am using webpack, dependencies are through npm. I don’t know how to configure properly with webpack for CDN based js libs. My current work around is to put


in html.js. while all other dependencies are in npm. It is not ideal. Is there a proper way to add epicenter js in webpack?

Update 3:
I added a line into package.json file under epicenter’s node module, “main”: “dist/epicenter.js”,
“name”: “Epicenter-JS-Libs”,
“version”: “1.5.0”,
“main”: “dist/epicenter.js”,
“repository”: {
“type”: “git”,
“url”: “git+https://github.com/forio/epicenter-js-libs.git”
},

Now it compiles. However, when it runs, it spits error “src/managers/auth-manager.js:101
AuthManager.prototype = $.extend(AuthManager.prototype, {
^
ReferenceError: $ is not defined”

I have installed jquery separately, and import it in my js file. But it doesn’t matter, still the same error. Now I go back to use html src= as workaround. Hope get more help from you for using it as local module.

Update 2: see comment

Update 1: see comment

Do you mean support for getting deploying your libraries? Or working with it locally? If the latter you should be able to just do "epicenter-js-libs": "https://github.com/forio/epicenter-js-libs.git in your package.json and that’ll install it in the right places. We use Bower internally to do this (i.e., fetch front-end dependencies), and I haven’t tried Webpack personally but this should still work. Let me know if I mis-understood your question.

Hi Neran,
Yes, I mean working with it locally. I tried to add to my package.json and run “npm install” after. It still not working. Here’s part of my package.json.

“dependencies”: {
“babel-core”: “5.8.25”,
…more ignored…
“superagent”: “1.4.0”,
“epicenter-js-libs”: “https://github.com/forio/epicenter-js-libs.git
},

Here’s what I put in my js file.
import F from ‘epicenter-js-libs’;

Run npm run build. Error message is “ERROR in ./src/components/VSListPage/VSListPage.js
Module not found: Error: Cannot resolve module ‘epicenter-js-libs’ in /Users/jayma/Dev/AirPunch/SPS/spsweb/src/components/VSListPage
@ ./src/components/VSListPage/VSListPage.js 39:23-51”

also “npm ls” give error message saying it require @version number.

Update 2
I have been able to install it locally with
npm install --save github:forio/epicenter-js-libs.git

It downloaded files into node_modules dir and added following lines into package.json
“Epicenter-JS-Libs”: “forio/epicenter-js-libs”,

However, I still cannot import the lib in my js file neither following method works. How can I import it properly? Thanks
import F from ‘Epicenter-JS-Libs’;
const F = require(‘Epicenter-JS-Libs’);

Hi Jay,

An advantage using the ‘require’ approach is that you can just pick and choose which parts of the libraries you need and which ones you can skip - and as such, there is no ‘export all’ in the libraries. But, if you look at app.js in the jsLibs all that does is provide a namespace over individually required modules. So in essence you should be able to write your own version of app.js which just pulls in what you need. i.e., you’d do require('Epicenter-JS-Libs/managers/run-manager'); to just the run-manager and so on. Does that make sense?

I’m also open to make a global export object which exports everything in the next release if you find picking modules one-by-one to be redundant/confusing.

1 Like

Hi Neran,

I am sure it makes sense. My issue now is still about it’s not working. The way you told me put a line in package.json did not work. I tried other things in described in update 2, 3 do not work. So far I cannot make local package to work. Once it works, I surely will use the better practice you suggest.

Jay

Hi Jay,

Which part are you having trouble with? Doing require('Epicenter-JS-Libs/managers/run-manager') does not import it?

-Naren

I manage to put the line in package.json, somehow it did not work before. Now I have Epicenter-JS-Libs installed under node_modules. But I still get error:
ERROR in ./src/components/VSListPage/VSListPage.js
Module not found: Error: Cannot resolve module ‘Epicenter-JS-Libs/service/data-api-service’ in …

my code to require it:
require(‘Epicenter-JS-Libs/service/data-api-service’);