adding npm libary to dependencies
See original GitHub issueI used the simple-json-datasource Plugin and added the mqtt library github.com/mqttjs/MQTT.js like so:
I ran npm install mqtt --save
in the simple-json-datasource folder, so it would be in the package.json as a dependency.
in the datasource.js I added:
import mqtt from "mqtt";
afterwards I ran the grunt task which build the src files to the dist folder.
I also ran npm install mqtt --save
in the grafana folder and ran the grunt task there also,
but I always get the following error when I try to add my simple-json-datasource Plugin:
Plugin Error Error loading http://localhost:3000/public/mqtt as “mqtt” from http://localhost:3000/public/plugins/grafana-simple-json-datasource/datasource.js
I cant figure out how to add a external library to the datasource Plugin and get it running, do I miss out something?
I would be very thankful for some help or advice on how to use npm libraries which arent included in grafana by default. I couldnt find any information regarding that matter.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:7
- Comments:6 (1 by maintainers)
@LaPush I came across the same issue with including additional dependency. I used this experimental plugin as boilerplate to tackle this issue: https://github.com/NatelEnergy/grafana-plotly-panel/
src/external/
src/external/mqtt.js
. (Actually even Grafana project has vendors in git repository https://github.com/grafana/grafana/tree/master/public/vendor)external
folder, so yourGruntfile.js
should be like:import * as mqtt from './external/mqtt';
When running npm install you will download that package into node_modules. Which is not available for grafana. To use npm packages you need to first download them and then copy them from node_modules to the rootfolder/dist folder.