#Error: Cannot find module 'mqtt' but it is installed

1 messages · Page 1 of 1 (latest)

static sky
#

Heyho, see picture.
mqtt is installed, i checked via ``npm list-g`. Why do i run into this error the whole time?
Thanks

#
root@raspberrypi:/home/pi# npm list -g
/usr/local/lib
├── corepack@0.17.0
├── mqtt@4.3.7
├── n@2.1.12
├── node-gyp@3.7.0
├── node-red@3.0.2
└── npm@9.6.5
#

I also did npm install in the mqtt package folder

#

Im so confused

#

If u ask what code the furkan.js is, it is this ```js
const mqtt = require('mqtt')
const client = mqtt.connect('mqtt://test.mosquitto.org')

client.on('connect', function () {
client.subscribe('presence', function (err) {
if (!err) {
client.publish('presence', 'Hello mqtt')
}
})
})

client.on('message', function (topic, message) {
// message is Buffer
console.log(message.toString())
client.end()
})

#

It is just an example code to test if its working

#

And for some fking reason it says mqtt module not found but its clearly installed??

woven sage
#

why is it installed globally though?

#

that probably isn't the issue but it should be installed locally to the project

static sky
#

I tried both ways, lots of articles say do globally

#

not global woul be just without -g i guess?

woven sage
#

yes

static sky
#

what defines a "project"

#

sorry im new to js and node

#

I just have this file i want to make run KEKWcry

#

but as u said it shouldnt be the issue anyway

woven sage
static sky
#

do i just run npm install mqtt in the same folder where the .js file is?

woven sage
# static sky what defines a "project"

a project is a directory which holds your package.json and node_modules and whatever source and asset files you may have, ie basically your entire project is there

#

it's created automatically if you do npm install locally or if you do npm init

static sky
#

omfg

#

that was it

#

i wasted too much time on this

woven sage
static sky
#

thanks