Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build using Typescript error: Cannot use namespace 'SerialPort' as a type. #342

Open
Zandor300 opened this issue Jul 2, 2024 · 6 comments

Comments

@Zandor300
Copy link
Contributor

Receiving the following error if I want to build using Typescript. Before I was just running the plain Javascript.

jsmodbus:           4.0.6 (Since that is the last one published on npm)
serialport:        12.0.0
@types/serialport:  8.0.5
typescript:         5.5.3
$ tsc
node_modules/jsmodbus/dist/modbus-rtu-client.d.ts:6:55 - error TS2709: Cannot use namespace 'SerialPort' as a type.

6 export default class ModbusRTUClient extends MBClient<SerialPort, ModbusRTURequest> {
                                                        ~~~~~~~~~~

node_modules/jsmodbus/dist/modbus-rtu-client.d.ts:9:25 - error TS2709: Cannot use namespace 'SerialPort' as a type.

9     constructor(socket: SerialPort, address: number, timeout?: number);
                          ~~~~~~~~~~

node_modules/jsmodbus/dist/modbus-rtu-server.d.ts:6:25 - error TS2709: Cannot use namespace 'SerialPort' as a type.

6     constructor(socket: SerialPort, options?: Partial<IModbusServerOptions>);
                          ~~~~~~~~~~

node_modules/jsmodbus/dist/rtu-client-request-handler.d.ts:7:83 - error TS2709: Cannot use namespace 'SerialSocket' as a type.

7 export default class ModbusRTUClientRequestHandler extends MBClientRequestHandler<SerialSocket, ModbusRTURequest> {
                                                                                    ~~~~~~~~~~~~

node_modules/jsmodbus/dist/rtu-client-request-handler.d.ts:11:25 - error TS2709: Cannot use namespace 'SerialSocket' as a type.

11     constructor(socket: SerialSocket, address: number, timeout?: number);
                           ~~~~~~~~~~~~


Found 5 errors in 3 files.

@stefanpoeter
Copy link
Member

The module is build against serialport version "serialport": "^7.1.5" see package.json.

@Zandor300
Copy link
Contributor Author

@stefanpoeter I use it with serialport v12 and it works fine, only the exact types used are incorrect when building using Typescript.

@stefanpoeter
Copy link
Member

That sounds like incompatibilties. If you want to port I am happy for any PR. As said it is compatible to 7.1.5.

@swisspol
Copy link

This seems to work around the compiling issue in TypeScript:

npm install serialport@9
npm i --save-dev @types/serialport

@stefanpoeter
Copy link
Member

Have you checked adding this to the package.json?

@Oniokey
Copy link

Oniokey commented Dec 14, 2024

This seems to work around the compiling issue in TypeScript:

npm install serialport@9
npm i --save-dev @types/serialport

Both the @9 version and the latest version of SerialPort raise the same issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants