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

Hi everyone,
I have succeeded in sharing components (client-code) between plugins (at How to share components among Kibana plugins?).
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.

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.

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

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

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

Hope that helps :slight_smile:

1 Like

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