[7.2] Kibana plugin development possible bug

Hi there!

I'm having some problems developing a kibana plugin for this specific Kibana version.
If I make EXACTLY the same steps which I'm about to describe to develop the plugin for version 7.0 or 7.1 or even 7.3, it works flawlessly. With version 7.2 I have the following error.

My steps are:

git clone https://github.com/elastic/kibana
cd kibana
git checkout 7.2

Here I can see the .node-version is the same I am using (10.15.2). Perfect.

yarn kbn bootstrap

Here it gives me some warnings like:

warning Resolution field "core-js@2.5.3" is incompatible with requested version "core-js@^2.6.5"
warning Resolution field "@types/node@10.12.27" is incompatible with requested version "@types/node@8.5.8"
warning Resolution field "@types/node@10.12.27" is incompatible with requested version "@types/node@8.5.8"
warning Resolution field "@types/node@10.12.27" is incompatible with requested version "@types/node@8.5.8"
warning Resolution field "@types/node@10.12.27" is incompatible with requested version "@types/node@8.5.8"
[3/5] Fetching packages...
info fsevents@1.2.7: The platform "linux" is incompatible with this module.
info "fsevents@1.2.7" is an optional dependency and failed compatibility check. Excluding it from installation.
[4/5] Linking dependencies...
warning " > @elastic/charts@4.2.6" has incorrect peer dependency "@elastic/eui@10.4.1".
warning "workspace-aggregator-bc398412-e147-4630-89fa-8201a4e98573 > x-pack > @mapbox/mapbox-gl-draw@1.1.1" has inco
rrect peer dependency "mapbox-gl@>=0.27.0 <=0.51.0".
warning "workspace-aggregator-bc398412-e147-4630-89fa-8201a4e98573 > x-pack > react-shortcuts@2.0.0" has incorrect p
eer dependency "react@^0.14.8 || ^15".
warning "workspace-aggregator-bc398412-e147-4630-89fa-8201a4e98573 > x-pack > react-shortcuts@2.0.0" has incorrect p
eer dependency "react-dom@^0.14.8 || ^15".
warning "workspace-aggregator-bc398412-e147-4630-89fa-8201a4e98573 > x-pack > graphql-code-generator > @graphql-modu
les/epoxy@0.1.9" has unmet peer dependency "@graphql-modules/logger@*".

But it keeps bootstrapping and finally succeeds.
Then I go

`node scripts/generate_plugin.js my_sample_plugin` answering:
`? Provide a short description This is a sample plugin`
`? What Kibana version are you targeting? 7.2.2`
`? Should an app component be generated? Yes`
`? Should translation files be generated? No`
`? Should a hack component be generated? No`
`? Should a server API be generated? Yes`
`? Should SCSS be used? Yes`

It keeps loading (returning the same above-mentioned warnings) and it finally says:

Bootstrapping completed!

Done in 168.27s.
success 🎉

  Your plugin has been created in plugins/my_sample_plugin. Move into that directory to run it:

    cd "plugins/my_sample_plugin"
    yarn start

Which is exactly what it says with version 7.3.
Problem is that now if I go to plugins/my_sample_plugin and run yarn start it immediately returns the error:

yarn run v1.19.1
warning package.json: No license field
$ plugin-helpers start
Task "start" failed:

Error: spawnSync node ENOENT
    at Object.spawnSync (internal/child_process.js:990:20)
    at spawnSync (child_process.js:601:24)
    at execFileSync (child_process.js:629:13)
    at module.exports (/home/fabio/Scrivania/kibana_7.2_test_plugin/kibana/packages/kbn-plugin-helpers/tasks/start/start_action.js:43:3)
    at run (/home/fabio/Scrivania/kibana_7.2_test_plugin/kibana/packages/kbn-plugin-helpers/lib/run.js:30:10)
    at Command.<anonymous> (/home/fabio/Scrivania/kibana_7.2_test_plugin/kibana/packages/kbn-plugin-helpers/lib/commander_action.js:27:13)
    at Command.listener (/home/fabio/Scrivania/kibana_7.2_test_plugin/kibana/packages/kbn-plugin-helpers/node_modules/commander/index.js:315:8)
    at Command.emit (events.js:189:13)
    at Command.parseArgs (/home/fabio/Scrivania/kibana_7.2_test_plugin/kibana/packages/kbn-plugin-helpers/node_modules/commander/index.js:654:12)
    at Command.parse (/home/fabio/Scrivania/kibana_7.2_test_plugin/kibana/packages/kbn-plugin-helpers/node_modules/commander/index.js:474:21)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

This thing is really driving me nuts since I really need to develop the plugin for the 7.2 version and apparently that is the only version returning this error.

At first I thought it was linked to the fact the from version 7.1 to 7.2 they changed the folder where the plugin is created (from kibana-extra/ sibling of kibana/ to the plugins/ which is a child of kibana/) but then I tried with version 7.3 which creates the plugin inside the plugins/ folder as well and it worked, so I really do not know what to do about it.

Thank you for your support!

Check here may help https://github.com/elastic/kibana/issues/16784

Also, I checked the differences between those files return in the errors (e.g. /home/fabio/Scrivania/kibana_7.2_test_plugin/kibana/packages/kbn-plugin-helpers/tasks/start/start_action.js and all the others) and the equivalent files of the 7.3 version and they are identical (I used the diff linux command).

Any ideas?

Check here may help https://github.com/elastic/kibana/issues/16784

Hi and thanks for the tip.

Though, I tried setting export KIBANA_ROOT="/home/fabio/Scrivania/kibana_7.2_test_plugin/kibana" but it doesn't seem to work anyway. Now it returns

`Error: The 'KIBANA_ROOT' environment variable has been removed from '@kbn/plugin- helpers'. During development your plugin must be located in '../kibana-extra/{pluginName}' relative to the Kibana directory to work with this package.`

Which makes me laugh because it automatically creates it into the plugins/ folder.
Though, I tried moving it into the ../kibana-extra/ folder (relative to kibana/) but it doesn't work and returns

yarn run v1.19.1
warning package.json: No license field
$ plugin-helpers start
/bin/sh: 1: plugin-helpers: not found
error Command failed with exit code 127.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

I think the suggestion to move it into ../kibana-extra/ is a old one which they forgot to remove.

So, what am I missing?

Could your help :
1- What OS you are using ?
2. What branch did you clone from github ?

I used to work with all 7.x and master (8) under window and never get this error

I'm using Linux Mint 18.3 KDE and I cloned the master branch as you can see from the steps in the first message of the thread.

But again I find it so strange that only version 7.2 gives me that error. Neither the previous versions nor the following ones. Unbelievable.

If you follow those steps won't you get that error?

try with checking out a stable tag
git checkout tags/v7.2.0

Same problem.

I tried git checkout tags/v7.2.0 as you suggested. Run the yarn kbn bootstrap and the node scripts/generate_plugin my_plugin again.

When it comes to run the yarn start from inside the my_plugin folder it returns the usual error.

Do you think there will might be any error if I develop the plugin for the 7.3 version and then downgrade it in the package.json to the 7.2?

Yet, I find it incredible :thinking:

did you tried yarn start outside of plugins folder, from Kibana home for example
Check if plugins/my_plugin contains a folder node_modules
Usually we develop under master and we build against a stable release 7.4, 7.3 and 7.2 with no issues

Yes, if I run yarn start from the kibana/ folder it runs. Now I'm about to replace the node_modules/ folder in the kibana/plugins/my_plugin/ folder with the one from kibana/ and see if it works.

If it doesn't, I'll make another post with all my steps from the cloning of the repo to the failing yarn start with all the screenshots so it's gonna be easier for you helping me debug it.

Thanks

Usually when i use node scripts/generate_plugin my_plugin it create automtically node_modules in all plugins under $KIBANA_HOME/plugins

Exactly and in fact it does create the node_modules inside $KIBANA_HOME/plugins/my_plugin. Problem is that yarn start works in $KIBANA_HOME but not in $KIBANA_HOME/plugins/my_plugin and I cannot understand why.

It only happens with version 7.2.x, not with version 7.1, nor with 7.3.

Here's the step-by-step procedure I followed:

  1. Create a folder KIBANA_PLUGIN_TEST_7.2 inside the Desktop and move there

  2. Cloning the kibana repo from github (git clone https://github.com/elastic/kibana.git)

  3. Cd into the cloned kibana repo (cd kibana) and check the git status (git st) to verify I'm on branch master

  4. Checking out to stable version 7.2.0 (git co tags/v7.2.0)

  5. Run yarn kbn bootstrap from inside the kibana/ folder (you can see the warnings while bootstrapping)

  6. Bootstrapping successfully completed and working yarn start from kibana/ folder

  7. Generate the my_plugin plugin (node scripts/generate_plugin.js my_plugin) with all the due choices

  8. See the usual warnings during the plugin generation

  9. Plugin successfully generated

  10. Move into plugins/my_plugin and run yarn start. Damn error is returned

I want to point out my node --version returns v10.15.2, so it should be ok.

Sorry for the length of the post but this way you can really follow me throughout all the steps.
What is going wrong and WHY only with the 7.2?

Try to run yarn kbn bootstrap inside the generated plugin then run yarn start

Same problem :no_good_man:

Very strange your case :slight_smile:
In https://github.com/elastic/kibana/tree/master/packages/kbn-plugin-generator
There is a big > NOTE: All of these scripts should be run from the generated plugin.

Yep but the first time I guess I have to run yarn kbn bootstrap from the kibana/ folder, otherwise I do not think the node scripts/generate_plugin.js would properly run.

Then, I tried everything (also running yarn kbn bootstrap from inside the plugin folder) but it always returns the same error.

As I said, I think I'll try to develop the plugin for the 7.3 and then (after the build) I'll simply change in the package json the 7.3.3 to 7.2.0. Do you think there will be any compatibility problems?

Thank you

Go ahead with 7.3 or even with 7.4, you may have small issues but really minor, some enhancement or breaking changes in UI components (https://elastic.github.io/eui/#/)

I think I'll go with that!

Thank you. Anyway, if I found an explanation to all this, I'll write it here.

P.S. think I'm gonna try it out on a different Linux distro, too.

Ok I guess I found the problem with the help of a colleague of mine.

Reading the error there's a call to kbn-plugin-helpers/tasks/start/start_action.js.

Going back through all the linked files we noticed there's a line in packages/kbn-plugin-helpers/lib/plugin_config.js which refers to the old folder structure, calling the path ../../kibana as if the plugin was placed inside the old kibana-extra folder.

The error

`Error: The 'KIBANA_ROOT' environment variable has been removed from '@kbn/plugin- helpers'. During development your plugin must be located in '../kibana-extra/{pluginName}' relative to the Kibana directory to work with this package.`

should have rung a bell about it.

Then we went with git blame packages/kbn-plugin-helpers/lib/plugin_config.js from which you can see that Tiago Costa applied a fix to that path in commit e4830625.

Thus, running git show e4830625 | git apply from v7.2.0 branch, you can see that some files got modified

It'll then be sufficient to add the edits (git add .) and commit ignoring the linter (git commit -m "whatever" --no-verify).

Now, running the yarn kbn bootstrap, node scripts/generate_plugin.js my_plugin and cd plugins/my_plugin/, yarn start everything works as expected.

It's kinda strange that such an important fix is not mentioned anywhere (apart from git history) and I really do not understand how it could work on your environment.
You sure replicated my exact steps, cloning the repo, checking out to 7.2.0 and running everything else without changing anything? Since it really shouldn't work because of that wrong path.

Anyway, hope this thread will be of help to anybody who needs to develop a plugin for Kibana 7.2.x.

2 Likes