# \[Kibana 7.5\] How to share server's code between plugins?

**URL:** <https://discuss.elastic.co/t/kibana-7-5-how-to-share-servers-code-between-plugins/220582>\
**Category:** Kibana\
**Created:** [February 24, 2020, 7:47am UTC](https://discuss.elastic.co/t/kibana-7-5-how-to-share-servers-code-between-plugins/220582 "2020-02-24T07:47:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![lvdiev](https://avatars.discourse-cdn.com/v4/letter/l/c77e96/32.png) [@lvdiev](https://discuss.elastic.co/u/lvdiev)\
**Post date:** [February 24, 2020, 7:47am UTC](https://discuss.elastic.co/t/kibana-7-5-how-to-share-servers-code-between-plugins/220582/1 "2020-02-24T07:47:27Z")

</div>

Hi everyone,  
I have succeeded in sharing components (client-code) between plugins (at [How to share components among Kibana plugins?](https://discuss.elastic.co/t/how-to-share-components-among-kibana-plugins/219890/2)).  
I assumed that there must the similar way to share server code, but no luck.  
I exported things of `'plugin_commons'` from `server/index.ts`. Then from other plugins, I use  
`import * as commons from 'plugins/plugin_commons'`  
It won't work and will throw error  
` FATAL Error: Cannot find module 'plugins/plugin_commons'`

How can I get it work? Thanks.

---

<div class="post-metadata">

**Author:** ![tsullivan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tsullivan/32/31077_2.png) [@tsullivan](https://discuss.elastic.co/u/tsullivan)\
**Post date:** [February 24, 2020, 8:55pm UTC](https://discuss.elastic.co/t/kibana-7-5-how-to-share-servers-code-between-plugins/220582/2 "2020-02-24T20:55:07Z")

</div>

I looked back at the original post. Thanks for including that, it had a lot of good context.

I think `import {DateRangePicker} from 'plugins/plugins_commons';` only works in UI code because it uses a trick provided by the way Kibana bundles the UI code for the browser. In server code, `import` only works for the actual filesystem reference.

```auto
import {DateRangePicker} from '../../path/to/root/of/plugins/common/server';

```

---

<div class="post-metadata">

**Author:** ![lvdiev](https://avatars.discourse-cdn.com/v4/letter/l/c77e96/32.png) [@lvdiev](https://discuss.elastic.co/u/lvdiev)\
**Post date:** [February 25, 2020, 7:11am UTC](https://discuss.elastic.co/t/kibana-7-5-how-to-share-servers-code-between-plugins/220582/3 "2020-02-25T07:11:46Z")

</div>

Thank you for your answer.  
BTW, is it the same in latest version of Kibana?

---

<div class="post-metadata">

**Author:** ![tsullivan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tsullivan/32/31077_2.png) [@tsullivan](https://discuss.elastic.co/u/tsullivan)\
**Post date:** [February 25, 2020, 6:22pm UTC](https://discuss.elastic.co/t/kibana-7-5-how-to-share-servers-code-between-plugins/220582/4 "2020-02-25T18:22:58Z")

</div>

Yes the server-side imports in Kibana work the same in the master branch as in the example I posted

Hope that helps 🙂

---

<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:** [March 24, 2020, 6:23pm UTC](https://discuss.elastic.co/t/kibana-7-5-how-to-share-servers-code-between-plugins/220582/5 "2020-03-24T18:23:07Z")

</div>

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