TypeError: Cannot read properties of undefined (reading 'client')
alishefaee opened this issue · 1 comments
alishefaee commented
When using typescript, I get this error:
16:04:12 error unhandledRejection: Cannot read properties of undefined (reading 'client')
TypeError: Cannot read properties of undefined (reading 'client')
this is my snippet code:
// typescript
import { Socket, SocketConnectOpts } from 'net'
import Modbus from "jsmodbus";
let modbusSocket = new Socket()
const client = new Modbus.client.TCP(modbusSocket)
package.json:
{
"main": "index.ts",
"homepage": "https://github.com/alishefaee/jti-energy-management#readme",
"dependencies": {
"@types/express": "^4.17.15",
"express": "^4.18.2",
"jsmodbus": "^4.0.6",
"socket.io": "^4.6.1",
"typescript": "^4.9.4",
},
"devDependencies": {
"ts-node-dev": "^2.0.0"
}
}
What I tried:
If I use
const Modbus = require('jsmodbus')
instead of:
import Modbus from "jsmodbus";
problem is solved.
Also there is no problem with js version.
carlmasonemr commented
I found specifically importing client resolved this for me:-
import { client } from 'jsmodbus';