# Dealing with Kibana plugin server dependencies that won't run in the browser

**URL:** <https://discuss.elastic.co/t/dealing-with-kibana-plugin-server-dependencies-that-wont-run-in-the-browser/293599>\
**Category:** Kibana\
**Tags:** kibana-plugin-development\
**Created:** [January 5, 2022, 9:52pm UTC](https://discuss.elastic.co/t/dealing-with-kibana-plugin-server-dependencies-that-wont-run-in-the-browser/293599 "2022-01-05T21:52:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Specialist](https://avatars.discourse-cdn.com/v4/letter/s/e480ec/32.png) [@Specialist](https://discuss.elastic.co/u/Specialist)\
**Post date:** [January 5, 2022, 9:52pm UTC](https://discuss.elastic.co/t/dealing-with-kibana-plugin-server-dependencies-that-wont-run-in-the-browser/293599/1 "2022-01-05T21:52:05Z")

</div>

Hello again,

during Kibana plugin development I came across the following issue:

In the plugin's server part I'd like to use a dependency (currently declared via the plugin's `package.json`), which only works under node.js (such as `amqplib`). Unfortunately, this causes `yarn start` as well as the plugin build to fail as webpack won't find the dependencies transitive `net` dependency (that won't work in the browser).

Is the a way to exclude a certain dependency for a plugin's frontend build (via webpack triggered by `@kbn/optimizer` from `plugin-helper`) and only use it in the backend?

Alternatively, is there a way to amend the webpack configuration used by the optimizer?

Thanks!

Edit: I could probably fork off a backend-only (`ui: false`) plugin, which skips the optimizer, but that feels ugly due to the fact that I would have to call the backend-only plugin via HTTP and couldn't provide a JS/TS API (which would again trigger the optimizer)...

---

<div class="post-metadata">

**Author:** ![Mikhail\_Shustov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mikhail_shustov/32/49186_2.png) [@Mikhail\_Shustov](https://discuss.elastic.co/u/Mikhail_Shustov)\
**Post date:** [January 10, 2022, 12:21pm UTC](https://discuss.elastic.co/t/dealing-with-kibana-plugin-server-dependencies-that-wont-run-in-the-browser/293599/2 "2022-01-10T12:21:57Z")

</div>

> Unfortunately, this causes `yarn start` as well as the plugin build to fail as webpack won't find the dependencies transitive `net` dependency (that won't work in the browser).

IIRC Kibana doesn't use `webpack` to build server-side dependencies. nodejs code is compiled by `babel` [https://github.com/elastic/kibana/blob/eb9001d1841d98c4854714e21c11f83a054a5df7/packages/kbn-optimizer/src/node/node\_auto\_tranpilation.ts](https://github.com/elastic/kibana/blob/eb9001d1841d98c4854714e21c11f83a054a5df7/packages/kbn-optimizer/src/node/node_auto_tranpilation.ts)  
Are you sure that the server-side code is not imported by the client-side module accidentally? If it does, it's better to remove that import so it won't be processed by `webpack` anymore. Would you mind attaching an error stack trace if it doesn't help?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [February 7, 2022, 12:22pm UTC](https://discuss.elastic.co/t/dealing-with-kibana-plugin-server-dependencies-that-wont-run-in-the-browser/293599/3 "2022-02-07T12:22:52Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
