DEV Community

Cover image for Angular 10 + Storybook + npm package = NG Design System πŸ’œ - Step-by-Step

Angular 10 + Storybook + npm package = NG Design System πŸ’œ - Step-by-Step

David Lorenz on October 15, 2020

! The Angular version used here is 10.x tldr - The Task was: Create a UI Kit with Angular that lives on its own and scales to multipl...
Collapse
 
babatos profile image
babatos • Edited

Hi,
I followed the steps to step "2.6.2. Using the library package through local binding". I installed npm link @your-company/pattern-lib but when I call selector of button component pl-button label="hello"/pl-button in app.component.html .Nothing display . I don't know why :( .Please help me to solve this issue.
my english is not good,please sympathize!

Collapse
 
activenode profile image
David Lorenz

How does your directory structure look like?

Where is your main repository and where is the library repository? Do you get any error message?

Collapse
 
babatos profile image
babatos • Edited

I think I fixed the error by adding ""preserveSymlinks": true" to "option:{ }" in Myapp/Angular.json file. It worked. But I don't understand why It work. Could you explain me, please?

I'm using :
Angular CLI: 13.0.3
Node: 16.13.1
Package Manager: npm 8.1.2
OS: win32 x64

Collapse
 
babatos profile image
babatos

I get the following error at runtime:

core.mjs:6484 ERROR TypeError: Cannot read properties of null (reading 'bindingStartIndex')
at Module.Ι΅Ι΅elementStart (:51648/vendor.js:34341)
at ButtonComponent_Template (:51648/main.js:280)
at executeTemplate (:51648/vendor.js:69548)
at renderView (:51648/vendor.js:69277)
at renderComponent$1 (:51648/vendor.js:70812)
at renderChildComponents (:51648/vendor.js:69112)
at renderView (:51648/vendor.js:69311)
at renderComponent$1 (:51648/vendor.js:70812)
at renderChildComponents (:51648/vendor.js:69112)
at renderView (:51648/vendor.js:69311)

I do not see any errors while compiling

Collapse
 
babatos profile image
babatos

can I put my code to git for you review code?

Thread Thread
 
activenode profile image
David Lorenz

Yes

Thread Thread
 
babatos profile image
babatos

thanks you very much. This is my github

github.com/tiendatlgbg/LibraryAngu...

Collapse
 
messages2raja profile image
messages2raja

Hi,
I followed the steps and created a sample package and published in npm as well, But when I tried to consume the npm package I am getting the following err:
Cannot find module '@messages2raja/pattern-lib' or its corresponding type declarations.ts(2307)..Please help me to solve this issue.

Collapse
 
activenode profile image
David Lorenz

Can you provide more information where your @messages2raja /pattern-lib is located and how you installed it?

Collapse
 
messages2raja profile image
messages2raja

it is located in npmjs.org url: npmjs.com/package/@messages2raja/p...
I have installed it via the npm i command.

Thread Thread
 
activenode profile image
David Lorenz

I think i can see the problem. You were probably running npm publish in your root directory right?

That however would publish your whole angular project. What you want instead is build it and then go to dist/pattern-lib and run npm publish from there :)

Hope that solves it. I will enhance the article.

Collapse
 
ganicotte profile image
ganicotte • Edited

Hello David,

Thank you for this outstanding post it helped a lot !
There is one thing that keeps me struggling with : how do you reference your static assets in your Storybook ? Let's say you have an image in '/projects/pattern-lib/src/assets', and your button component uses it. How do you configure your webpack in order to display it on Storybook?

Cheers @activenode :)

Collapse
 
wahyufaturrizky profile image
Wahyu Fatur Rizki

hi @activenode I got this error please help me:

main.ts:7 Error: NG0203: inject() must be called from an injection context such as a constructor, a factory function, a field initializer, or a function used with EnvironmentInjector#runInContext. Find more at angular.io/errors/NG0203
at injectInjectorOnly (core.mjs:731:15)
at Module.Ι΅Ι΅inject (core.mjs:742:60)
at Object.MatCommonModule_Factory as useFactory
at Object.factory (core.mjs:8854:38)
at R3Injector.hydrate (core.mjs:8767:35)
at R3Injector.get (core.mjs:8655:33)
at injectInjectorOnly (core.mjs:738:33)
at Ι΅Ι΅inject (core.mjs:742:60)
at useValue (core.mjs:8435:65)
at R3Injector.resolveInjectorInitializers (core.mjs:8704:17)

Collapse
 
wesleyvdkop profile image
Wesley van der Kop

Hi David,

I would really like to know how to publish the angular framework as web components. Could you provide any information around this?

Collapse
 
activenode profile image
David Lorenz

dev.to didn't show me this comment. Is this still an open topic for you?

Collapse
 
wesleyvdkop profile image
Wesley van der Kop

Hi David,

That's not a problem I figured it out ;)

Collapse
 
p_leppard profile image
Paul Leppard • Edited

Awesome post. Can you post on how to create a component that animates in Storybook? I have created an accordion which utilises Angular Animations to toggle it open and closing but can't make it work in storybook with the animation. It just shows it as always open. Keep up the great work!

Collapse
 
andyleeboo profile image
Andy Lee

This is awesome. Looking forward to reading more about testing in Storybook. Good job πŸ‘

Collapse
 
millimetha profile image
Tanja Stuchels

Thank you! πŸ™ This has helped me a lot. I am also looking forward to read more about testing in Storybook.

Collapse
 
weklund profile image
Wes

Great post!! Thank you @activenode !

Testing with storybook :D

Collapse
 
activenode profile image
David Lorenz

Thanks a bunch. Good hint, I should be doing the Testing with Storybook now :)