I am using mediasoup library to create video calls with many people in one room. Having imported npm package, it gives me a message that it is undefined:
async createWorker() {
this.worker = await mediasoup.createWorker({
rtcMinPort: 2000,
rtcMaxPort: 2080,
});
logger.debug(`worker pid ${this.worker.pid}`);
this.worker.on("died", (error: any) => {
// This implies something serious happened, so kill the application
logger.error({
error: error.toString()
}, "mediasoup worker has died");
setTimeout(() => process.exit(1), 2000); // exit in 2 seconds
});
}
the error:
C:\Users\andri\Desktop\resume_projects\college_chat\back\src\messaging\socketManager\index.ts:22
this.worker = await mediasoup.createWorker({
^
TypeError: Cannot read properties of undefined (reading 'createWorker')
at SocketManager.<anonymous> (C:\Users\andri\Desktop\resume_projects\college_chat\back\src\messaging\socketManager\index.ts:22:35)
at Generator.next (<anonymous>)
at C:\Users\andri\Desktop\resume_projects\college_chat\back\src\messaging\socketManager\index.ts:31:71
at new Promise (<anonymous>)
at __awaiter (C:\Users\andri\Desktop\resume_projects\college_chat\back\src\messaging\socketManager\index.ts:27:12)
at SocketManager.createWorker (C:\Users\andri\Desktop\resume_projects\college_chat\back\src\messaging\socketManager\index.ts:47:16)
at SocketManager.<anonymous> (C:\Users\andri\Desktop\resume_projects\college_chat\back\src\messaging\socketManager\index.ts:123:16)
at Generator.next (<anonymous>)
at C:\Users\andri\Desktop\resume_projects\college_chat\back\src\messaging\socketManager\index.ts:31:71
at new Promise (<anonymous>)
My node version: v18.17.0 My python version: 3.10.7 I have MSBuild tools installed since I have visual studio on my laptop (I am on Windows). I have also tried to install this package as administator from a separate terminal - didn't work as well.
mediasoup here is imported by its default value, when it does not export a default value (undefined). createWorker is defined as a named export. You can either import all named exports as a variable import * as mediasoup
or import just createWorker import {createWorker}
.
The package was installed successfully because if you was importing an invalid package, it would've thrown a "Cannot find module" error.