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

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)...

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
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?

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