# Build plugin failing at last stage with ERROR Error: Premature close

**URL:** <https://discuss.elastic.co/t/build-plugin-failing-at-last-stage-with-error-error-premature-close/360110>\
**Category:** Kibana\
**Tags:** elastic-stack-monitoring, elastic-stack-security, elastic-stack-alerting\
**Created:** [May 24, 2024, 2:05am UTC](https://discuss.elastic.co/t/build-plugin-failing-at-last-stage-with-error-error-premature-close/360110 "2024-05-24T02:05:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sunil\_Jagtap](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sunil_jagtap/32/133604_2.png) [@Sunil\_Jagtap](https://discuss.elastic.co/u/Sunil_Jagtap)\
**Post date:** [May 24, 2024, 2:05am UTC](https://discuss.elastic.co/t/build-plugin-failing-at-last-stage-with-error-error-premature-close/360110/1 "2024-05-24T02:05:34Z")

</div>

Hi Everyone,

As per the documentation : [Plugin tooling | Kibana Guide [8.5] | Elastic](https://www.elastic.co/guide/en/kibana/8.5/plugin-tooling.html)

Topic : Build plugin distributable  
To build your plugin run within your plugin folder:

yarn build

It will output a`zip` archive in kibana/plugins/my\_plugin\_name/build/ folder.

It is failing with below error :

```auto
info [kibana] Creating deb package
info $ fpm --force -t deb --package /Users/sunil/Documents/workspace/kibana/target/NAME-8.5.1-SNAPSHOT-ARCH.TYPE -s dir --name kibana --description Explore and visualize your Elasticsearch data --version 8.5.1-SNAPSHOT --url https://www.elastic.co --vendor Elasticsearch, Inc. --maintainer Kibana Team......... [BIG TEXT]

   │ERROR failure 0 sec
   │ERROR Error: Premature close
   │ at new NodeError (node:internal/errors:387:5)
   │ at Socket.onclose (node:internal/streams/end-of-stream:140:30)
   │ at Socket.emit (node:events:525:35)
   │ at Pipe.<anonymous> (node:net:301:12)

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

```

looking for help.

---

<div class="post-metadata">

**Author:** ![nickpeihl](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nickpeihl/32/112622_2.png) [@nickpeihl](https://discuss.elastic.co/u/nickpeihl)\
**Post date:** [May 24, 2024, 2:20pm UTC](https://discuss.elastic.co/t/build-plugin-failing-at-last-stage-with-error-error-premature-close/360110/2 "2024-05-24T14:20:03Z")

</div>

Hi @Sunil_Jagtap. Have you tried running `yarn kbn bootstrap` before running `yarn build`? If that still doesn't work, try running `yarn kbn clean && yarn kbn bootstrap`. Then try `yarn build` again.

---

<div class="post-metadata">

**Author:** ![gl-yziquel](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gl-yziquel/32/135150_2.png) [@gl-yziquel](https://discuss.elastic.co/u/gl-yziquel)\
**Post date:** [June 9, 2024, 12:50am UTC](https://discuss.elastic.co/t/build-plugin-failing-at-last-stage-with-error-error-premature-close/360110/3 "2024-06-09T00:50:11Z")

</div>

Exact same issue. And I did run yarn kbn bootstrap before yarn build.

The following instructions "work" in the sense that they (i.e. --skip-os-packages) disable the debian and distribution level packaging.

```fish
#!/usr/bin/env fish
nvm install (cat .nvmrc)
nvm use
corepack enable
yarn kbn bootstrap --force-install
node scripts/build --all-platforms --skip-os-packages

```

You may also do `yarn build --skip-os-packages` for the last line.

This error possibly appears because of missing dependencies such as `fpm`. Dunno.

Edit: This error is indeed due to missing `fpm`. To install `fpm`, do the following:

```console
gix clone https://github.com/jordansissel/fpm.git
cd fpm
bundle install
bundle exec gem build fpm.gemspec
gem install fpm-*.gem

```
