Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Publish library as a JS package on NPM #47

Closed
TwanoO67 opened this issue Mar 7, 2018 · 8 comments
Closed

Publish library as a JS package on NPM #47

TwanoO67 opened this issue Mar 7, 2018 · 8 comments

Comments

@TwanoO67
Copy link
Owner

TwanoO67 commented Mar 7, 2018

Hello Guys!

For the moment the package is published as a TS module.
So it is compiled with your typescript settings when you use it.

But this mode of using is not allowed with the new angular/cli versions.
So I would like to publish the package as a JS lib.

I already tried that on develop (i did a "yarn build" function, that produce a dist folder, and use that on the package.json).
But then when I use it on a project, it compile right, but it fail on loading, with errors like so:
Uncaught ReferenceError: UserService is not defined at eval (can-activate-guard.service.js:33) at eval (can-activate-guard.service.js:36) at Object../node_modules/ngx-admin-lte/dist/src/services/can-activate-guard.service.js (vendor.bundle.js:317)

It seems that the internal service aren't able to load each other anymore.

Does any of you already create a JS package on NPM and have some example to help me with that ?

Any idea would be much appreciated!

@fabioformosa
Copy link

I don't understand. Have you followed those steps to build and publish on npm registry?
https://codeburst.io/https-chidume-nnamdi-com-npm-module-in-typescript-12b3b22f0724

Have you searched/opened a stackoverflow issue for the error message you get?

@TwanoO67
Copy link
Owner Author

TwanoO67 commented Mar 8, 2018

Hello @fabioformosa

Yes its exactly the tutorial that I followed. And I achieve to have a working compilation and get it published on npm. The problem is only after when I try to install.

I tried searching on stackoverflow but the error seems to common and I didn't found answer that was matching the case

@TwanoO67
Copy link
Owner Author

TwanoO67 commented Mar 9, 2018

Hello guys!

The library as beed made compatible with angular >4
(tested with angular 6.0.0.beta-7)

If you want to try in a angular 6 project, then:
yarn add [email protected]

and in your angular-cli.json

  "assets": [
    { "glob": "**/*", "input": "../node_modules/ngx-admin-lte/public/assets", "output": "./assets" }
  ],
  "scripts": [
    "../node_modules/jquery/dist/jquery.min.js",
    "../node_modules/bootstrap/dist/js/bootstrap.min.js",
    "../node_modules/admin-lte/dist/js/app.min.js"
  ],

and in your style.css

  @import "../node_modules/angular2-toaster/toaster.css";
  @import "../node_modules/admin-lte/dist/css/AdminLTE.min.css";
  @import "../node_modules/admin-lte/dist/css/skins/_all-skins.min.css";
  @import "../node_modules/bootstrap/dist/css/bootstrap.min.css";
  @import "../node_modules/font-awesome/css/font-awesome.min.css";
  @import "../node_modules/ionicons/dist/css/ionicons.min.css";

@fabioformosa
Copy link

Great! I will test ASAP with angular 5.
What was the problem with npm release?

@TwanoO67
Copy link
Owner Author

TwanoO67 commented Mar 9, 2018

It was related to peerDependencies, now i builded with ng-packagr and it fixed =)

@catull
Copy link
Contributor

catull commented Mar 12, 2018

@TwanoO67 This issue is done now, am I missing anything ?

@TwanoO67
Copy link
Owner Author

Jquery was missing on beta-9, but it seems ok now on beta-10.

@catull
Copy link
Contributor

catull commented Mar 12, 2018

I disagree with jquery being a direct dependency, see issue #52.
I am fine with this issue closed, though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants