Express middleware – TypeError: Cannot write private member #nextId to an object whose class did not declare it

I’m writing a custom logger for my express JS app and I’m getting an error TypeError: Cannot write private member #nextId to an object whose class did not declare it in my middleware function. Here is some of my code:

logger.js:

const logger = new class Logger {
   // ....
   #nextId = 0;
   // ....
   setupMiddleware(req, res, next) {
        // ....
        if (!fs.existsSync(logFilename))
            this.#nextId = 0; // HERE IS THE ERROR
        // ...
        next();
   }
   // ...
}
module.exports = logger;

main.js:

// ... requirements
server.use(logger.setupMiddleware); // this is the function!!
server.use(express.json());
server.use(delEmptyData);
server.use(queryToBody);
server.use(logger.startMiddleware);
// ... routing
server.use(exceptionHandler); // Exception handling
server.use(logger.endMiddleware);
// ... rest of the code

I think that somehow the middleware does not provide this context or something, but I don’t have any idea how to solve this. (I also tried to make it all static, but I got more confusing errors)

Thanks!