Webpack error when updating panel variable using locationService.partial()

Hi, following the example here:

import { locationService } from '@grafana/runtime';
locationService.partial({ 'var-service': 'billing' }, true);

I get the console error

Uncaught TypeError: _grafana_runtime__WEBPACK_IMPORTED_MODULE_2__.locationService is undefined

Grafana v7.5.15

This is my code, does anyone know what this means? Thanks so much!

import React from 'react';
import { PanelProps } from '@grafana/data';
import { SimpleOptions } from 'types';
import { Button } from '@grafana/ui';
import { locationService } from '@grafana/runtime';

interface Props extends PanelProps<SimpleOptions> {}

export const SimplePanel: React.FC<Props> = ({ options, data, width, height }) => {

  const updateVar = () => {
    console.log('clicked');
    locationService.partial({ 'var-service': 'billing' }, true);
  }
    
  return (
    <div>
      <Button
        variant="primary"
        title="this is title"
        size="lg"
        className=""
        onClick={updateVar}
      >
        Click me
      </Button>
        
    </div>
  );
};



This was updated in a recent version of Grafana, here’s the docs for 7.5:

Note that you need to use getLocationSrv instead of the new locationService.

This has also now being outdated. See “LocationService replaces getLocationSrv” in Plugin migration guide | Grafana documentation for good examples on the latest methods.

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