React plugin: How to import backend_srv in .tsx file

I am developing a datasource plugin in Grafana using React and want to import BackendSrv class into my react datasource component. However the below code gives file not found error.

import { getBackendSrv, BackendSrv } from ‘app/core/services/backend_srv’;

The statement fails with error: Cannot find module ‘app/core/services/backend_srv’.ts(2307)

How can I successfully include BackendSrv in my plugin?

Thanks,
Prasad

The types are available in @grafana/runtime.

import { getBackendSrv } from ‘@grafana/runtime’; works for me.

1 Like