-
Notifications
You must be signed in to change notification settings - Fork 26
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
ReferenceError: require is not defined
while loading external middleware
#231
Comments
I was able to workaround this by patching this line locally: new Function(middlewareConfig).call({ require, app, logger: logger_1.default, allRoutes }); and using |
I am looking into a more appropriate way to handle this, but would you like to try a dynamic import? (async () => {
this.logger.info("inside middleware");
const express = await import("express");
this.app.use(express.json({ limit: '10mb' }));
this.app.use(express.urlencoded({ limit: '10mb', extended: true }));
this.app.use("/", this.allRoutes);
})(); I don't see any errors, but I haven't validated if the middlewares are actually applied. |
@shubhendumadhukar the snippet you provided works okay for me in case of importing (async () => {
const multer = await import("multer");
this.app.use(multer().any());
this.app.use("/", this.allRoutes);
})(); I get
with (() => {
const multer = this.require('multer');
this.app.use(multer().any());
this.app.use("/", this.allRoutes);
})(); |
I figured it works if I do (async () => {
const multer = (await import('multer')).default;
this.app.use(multer().any());
this.app.use("/", this.allRoutes);
})(); |
Describe the bug
I'm trying to increase the max request body size by registering this middleware:
The server crashes with the next error:
The text was updated successfully, but these errors were encountered: