# \[Stencil\] Publishing a Stencil component to npm

**URL:** <https://forum.ionicframework.com/t/stencil-publishing-a-stencil-component-to-npm/120940>\
**Category:** Stencil\
**Created:** [February 8, 2018, 7:14pm UTC](https://forum.ionicframework.com/t/stencil-publishing-a-stencil-component-to-npm/120940 "2018-02-08T19:14:18Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![AaronSterling](https://avatars.discourse-cdn.com/v4/letter/a/51bf81/32.png) [@AaronSterling](https://forum.ionicframework.com/u/AaronSterling)\
**Post date:** [February 8, 2018, 7:14pm UTC](https://forum.ionicframework.com/t/stencil-publishing-a-stencil-component-to-npm/120940/1 "2018-02-08T19:14:18Z")

</div>

Does anyone know how to publish a Stencil 0.2.3 component to npm? I can’t seem to follow the documentation correctly, and I get error messages that seems to contradict the docs. One such message:

> package.json “main” property is required when generating a distribution and must be set to:  
> dist/star-rating.js

even though the docs say main should be set to something else.

---

<div class="post-metadata">

**Author:** ![reedrichards](https://avatars.discourse-cdn.com/v4/letter/r/34f0e0/32.png) [@reedrichards](https://forum.ionicframework.com/u/reedrichards)\
**Post date:** [February 8, 2018, 7:16pm UTC](https://forum.ionicframework.com/t/stencil-publishing-a-stencil-component-to-npm/120940/2 "2018-02-08T19:16:33Z")

</div>

Let me 10 minutes, I did it today but I’ve to do some adjustments…

---

<div class="post-metadata">

**Author:** ![reedrichards](https://avatars.discourse-cdn.com/v4/letter/r/34f0e0/32.png) [@reedrichards](https://forum.ionicframework.com/u/reedrichards)\
**Post date:** [February 8, 2018, 7:30pm UTC](https://forum.ionicframework.com/t/stencil-publishing-a-stencil-component-to-npm/120940/3 "2018-02-08T19:30:04Z")

</div>

I could pack/publish with the “new” way but can’t include it in a project. I clear that up and comes with the solution (I’m trying this new way [https://github.com/ionic-team/stencil/issues/502](https://github.com/ionic-team/stencil/issues/502))

---

<div class="post-metadata">

**Author:** ![reedrichards](https://avatars.discourse-cdn.com/v4/letter/r/34f0e0/32.png) [@reedrichards](https://forum.ionicframework.com/u/reedrichards)\
**Post date:** [February 8, 2018, 7:34pm UTC](https://forum.ionicframework.com/t/stencil-publishing-a-stencil-component-to-npm/120940/4 "2018-02-08T19:34:27Z")

</div>

It’s working…let me 5 to document

---

<div class="post-metadata">

**Author:** ![AaronSterling](https://avatars.discourse-cdn.com/v4/letter/a/51bf81/32.png) [@AaronSterling](https://forum.ionicframework.com/u/AaronSterling)\
**Post date:** [February 8, 2018, 7:34pm UTC](https://forum.ionicframework.com/t/stencil-publishing-a-stencil-component-to-npm/120940/5 "2018-02-08T19:34:56Z")

</div>

Looks as though there’s a tool missing: npm run build-for-npm. I’ve used [ng-packagr](https://github.com/dherges/ng-packagr) to publish Angular components. Maybe when Stencil stabilizes I’ll throw together “stencil-packagr.”

I’ll try to follow what you’ve written as soon as you post it, thank you (and thank you to @dkundel).

---

<div class="post-metadata">

**Author:** ![reedrichards](https://avatars.discourse-cdn.com/v4/letter/r/34f0e0/32.png) [@reedrichards](https://forum.ionicframework.com/u/reedrichards)\
**Post date:** [February 8, 2018, 7:42pm UTC](https://forum.ionicframework.com/t/stencil-publishing-a-stencil-component-to-npm/120940/6 "2018-02-08T19:42:40Z")

</div>

I use to think as you do because I was trying to publish my StencilJS library/component from “inside” the dist folder, as I would do with an Angular/ng-packagr module. To do so, I was copying and editing manually `package.json` because I was facing the same issue as you did. But like @dkundel described, it’s possible to pack (and I guess publish) a StencilJS component from the `root` folder.

Like:

```
git clone https://github.com/ionic-team/stencil-component-starter my-component
cd my-component
git remote rm origin
npm install
npm run build
npm pack 

```

If you would like to add a README and LICENSE to the component, you could then edit `package.json` attribute `files` and add it there

```
"files": [
    "dist/", "readme.md", "LICENSE"
 ],

```

P.S.: I gonna edit my solution to import the component in a Ionic project within the next minutes and link it here

**UPDATE**

I just published my component again to npm, this works too with `npm publish`

---

<div class="post-metadata">

**Author:** ![AaronSterling](https://avatars.discourse-cdn.com/v4/letter/a/51bf81/32.png) [@AaronSterling](https://forum.ionicframework.com/u/AaronSterling)\
**Post date:** [February 8, 2018, 7:48pm UTC](https://forum.ionicframework.com/t/stencil-publishing-a-stencil-component-to-npm/120940/7 "2018-02-08T19:48:44Z")

</div>

What if the component has peer dependencies? Does that information end up in the tarball after npm pack?

---

<div class="post-metadata">

**Author:** ![reedrichards](https://avatars.discourse-cdn.com/v4/letter/r/34f0e0/32.png) [@reedrichards](https://forum.ionicframework.com/u/reedrichards)\
**Post date:** [February 8, 2018, 7:51pm UTC](https://forum.ionicframework.com/t/stencil-publishing-a-stencil-component-to-npm/120940/8 "2018-02-08T19:51:50Z")

</div>

I don’t have other dependencies in my component so I could not tell, but if I understand correctly, the `package.json` of the root of my component end up 1 to 1 (exactly the same) in my tarball

---

<div class="post-metadata">

**Author:** ![reedrichards](https://avatars.discourse-cdn.com/v4/letter/r/34f0e0/32.png) [@reedrichards](https://forum.ionicframework.com/u/reedrichards)\
**Post date:** [February 8, 2018, 8:08pm UTC](https://forum.ionicframework.com/t/stencil-publishing-a-stencil-component-to-npm/120940/9 "2018-02-08T20:08:14Z")

</div>

For the record, that’s the post where I try to describe how to import a Stencil component in an Ionic project

> [@EXAMPLE: Integration StencilJS Web Component in Ionic App](https://forum.ionicframework.com/t/example-integration-stenciljs-web-component-in-ionic-app/106083/5):
>
> I just gonna let that here because, at least for me now, the way to import the component built with Stencil into Ionic was a bit different First there is a description of what to do with angular on the official StencilJS website [https://stenciljs.com/docs/framework-integration](https://stenciljs.com/docs/framework-integration) What I did in case of Ionic (after having build and installed the component, named “my-component” in my case): Like describe above, the CUSTOM\_ELEMENTS\_SCHEMA need to be declared In app.modulte.ts an import should …

---

<div class="post-metadata">

**Author:** ![mhartington](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mhartington/32/137757_2.png) [@mhartington](https://forum.ionicframework.com/u/mhartington)\
**Post date:** [July 19, 2021, 9:51pm UTC](https://forum.ionicframework.com/t/stencil-publishing-a-stencil-component-to-npm/120940/10 "2021-07-19T21:51:25Z")

</div>

Closed on July 19, 2021, 9:51pm UTC


