# How to properly include @kbn packages in external plugins?

**URL:** <https://discuss.elastic.co/t/how-to-properly-include-kbn-packages-in-external-plugins/270474>\
**Category:** Kibana\
**Tags:** kibana-plugin-development\
**Created:** [April 18, 2021, 12:12am UTC](https://discuss.elastic.co/t/how-to-properly-include-kbn-packages-in-external-plugins/270474 "2021-04-18T00:12:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![starcatter](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/starcatter/32/87253_2.png) [@starcatter](https://discuss.elastic.co/u/starcatter)\
**Post date:** [April 18, 2021, 12:12am UTC](https://discuss.elastic.co/t/how-to-properly-include-kbn-packages-in-external-plugins/270474/1 "2021-04-18T00:12:48Z")

</div>

Hi, I'm trying to add i18n support to a plugin, when I add the dependency to `package.json` as

```
"@kbn/i18n": "link:../../packages/kbn-i18n" 

```

I get a version mismatch error:

```
ERROR [single_version_dependencies] Multiple version ranges for the same dependency
  were found declared across different package.json files. Please consolidate
  those to match across all package.json files. Different versions for the
  same dependency is not supported.

  If you have questions about this please reach out to the operations team.

  The conflicting dependencies are:

    @kbn/i18n
      1.0.0 => kibana, @kbn/interpreter, @kbn/ui-shared-deps, x-pack
      link:../../packages/kbn-i18n => opendistro_kibana_reports
error Command failed with exit code 1.

```

When I try to specify a version I'm told to use a `link:`

```
    ERROR [opendistro_kibana_reports] depends on [@kbn/i18n] but it's not using the local package. Update its package.json to the expected value below.
 info Additional debugging info:

 │ info actual: "@kbn/i18n": "1.0.0"
 │ expected: "@kbn/i18n": "link:../../packages/kbn-i18n"
 │ package: opendistro_kibana_reports (/home/superbob/FC/kibanaPlug/kibana/plugins/kibana-reports/package.json)
error Command failed with exit code 1.

```

How can I use @kbn packages then? I've looked at the kibana plugin list in search of examples and saw they hardly use any @kbn packages. Some use `@kbn/plugin-helpers`, which seems to no longer work either in 7.10.2 due to `@kbn/optimizer@1.0.0` missing. But that's beside the point, I want to get @kbn/i18n working. Please help.

---

<div class="post-metadata">

**Author:** ![aaron-nimocks](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aaron-nimocks/32/73965_2.png) [@aaron-nimocks](https://discuss.elastic.co/u/aaron-nimocks)\
**Post date:** [April 18, 2021, 1:26am UTC](https://discuss.elastic.co/t/how-to-properly-include-kbn-packages-in-external-plugins/270474/2 "2021-04-18T01:26:13Z")

</div>

If you use the [plugin generator](https://github.com/elastic/kibana/tree/master/packages/kbn-plugin-generator) all this can be setup, at least that's what I do (not a developer).

But the generator creates a package.json like so

```auto
{
  "name": "crud",
  "version": "0.0.0",
  "private": true,
  "scripts": {
    "build": "yarn plugin-helpers build",
    "plugin-helpers": "node ../../scripts/plugin_helpers",
    "kbn": "node ../../scripts/kbn"
  }
}

```

Then it can be imported like

```auto
import { i18n } from '@kbn/i18n';

```

Noticed you are using opendistro also which could be completely different. I don't have any experience with that.

---

<div class="post-metadata">

**Author:** ![starcatter](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/starcatter/32/87253_2.png) [@starcatter](https://discuss.elastic.co/u/starcatter)\
**Post date:** [April 18, 2021, 1:59am UTC](https://discuss.elastic.co/t/how-to-properly-include-kbn-packages-in-external-plugins/270474/3 "2021-04-18T01:59:35Z")

</div>

It looks like I don't need to explicitly include the `@kbn/i18n` dependency in my plugin's `package.json`. Thanks for making me look in the right place.

I still don't know how it's linked, but I'm happy as long as it works.

I also tried using `yarn kbn bootstrap --exclude [my_plugin]`, so `@kbn/pm` wouldn't stop me from using `"@kbn/i18n": "1.0.0"` instead of a `link:`, that also ran fine, although now I'm not sure if that dependency did anything.

Another quirk I found is that [packages/kbn-i18n/src/core/locales.js](https://github.com/elastic/kibana/blob/master/packages/kbn-i18n/src/core/locales.js) doesn't support a lot of locales, so while using `i18n.translate()` worked for my new locale, `FormattedMessage` from `@kbn/i18n/react` would print the `defaultMessage` value until I manually added my language to `locales.js`.

---

<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:** [May 16, 2021, 2:00am UTC](https://discuss.elastic.co/t/how-to-properly-include-kbn-packages-in-external-plugins/270474/4 "2021-05-16T02:00:27Z")

</div>

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