How to properly include @kbn packages in external plugins?

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:

      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.

If you use the 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

  "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

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

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

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

1 Like

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