Module not found error

Hello

I use windows 10 with WSL running Ubuntu on it.
WSL version: 2.4.12.0
Whenever i install a new node package in the grafana project it keeps making this module not found error. Also whatever package i install on the project doesnt work.
Did anybody have this problem before?How do i solve it?

Whenever i install a new node package in the grafana project

are you developing a plugin?

yes. a datasource plugin

what version of nodejs do you have in wsl.

I ran into tons of issues when using wsl, highly not recommend it, unless you want to lose your hair and age by 50 years +

hello
nodejs version in wsl is v22.12.0

1 Like

please share the steps you took so we can reproduce in our wsl environment

hello

commands i used are as followed:

npx @grafana/create-plugin@latest
cd
npm install

then i downloaded this module.

npm i ping

npm run dev
docker compose up

then i got the module not found errors.
modules like fs, child_process etc. not found
i tried to install them via npm i fs. but errors didnt go away

1 Like

works for me on Ubuntu 22.04.5

hello
did u try npm i ping only by itself or did u try to install it on a grafana plugin project?
cuz i tried to use the ping.sys.probe function and it created errors.

in my own grafana plugin I am developing. so are you saying when using the module in code or when installing it?

hello
yes. when i used the module in code it produced errors.

so please provide code sample. so far I don’t believe you have mentioned anything about code usage?

hello

code is in datasource.ts file
import ping from ‘ping’;<— this part is at the start of the script
I put the code below inside async testDatasource()
var hosts = [‘127.0.0.1’];
hosts.forEach(function(host){
ping.sys.probe(host, function(isAlive){
var msg = isAlive ? ‘host ’ + host + ’ is alive’ : ‘host ’ + host + ’ is dead’;
console.log(msg);
});
});

Is it an es6 enabled module? Look at the doc for it

hello
im not sure but i didnt find any references to es6 in the grafana docs

@neslihanyakay please share your full plugin code in a public repository. I can give it a spin and see if it is something in your plugin or your system.

It is likely something in your system and most likely related to nodejs.

Sometimes with WSL happens that there’s a global window version of nodejs and a local wsl version of nodejs, so make sure you have the correct one installed. (this sounds weird but we’ve have people with similar issues because of this problem with other tools.)

hello

i uploaded the code to github. its very bare bones right now. i just couldnt write much because of the errors.

Es6 is in reference to that ping npm module

Hi @neslihanyakay

I cloned your repository and managed to build it “as is” (nothing modified)

my steps:

  • clone
  • npm install
  • npm run build
❯ npm run build

> oracle@1.0.0 build
> webpack -c ./.config/webpack/webpack.config.ts --env production

assets by path *.md 2.57 KiB
  asset README.md 2.52 KiB [compared for emit] [from: README.md] [copied]
  asset CHANGELOG.md 53 bytes [compared for emit] [from: ../CHANGELOG.md] [copied]
asset module.js 49.9 KiB [compared for emit] [minimized] (name: module) 1 related asset
asset LICENSE 11.1 KiB [compared for emit] [from: ../LICENSE] [copied]
asset img/logo.svg 1.55 KiB [compared for emit] [from: img/logo.svg] [copied]
asset plugin.json 732 bytes [emitted] [from: plugin.json] [copied]
cached modules 138 KiB (javascript) 1.2 KiB (runtime) [cached] 90 modules
webpack 5.98.0 compiled successfully in 152 ms

which confirms there’s something wrong in your environment setup.

you can also try to go to https://codesandbox.io/p/github/neslihan26/grafana-plugin/main (might have to login, it is a free tool)

there you can use the terminal (left side bar) to run build and confirm it works.

hello
is es6 not compatible with grafana plugins? i couldnt see references to it in grafana docs