The server stops right away throwing this error. The layout of my template also breaks with no CSS. Please note that I'm not using any middleware, nor am I using next in my callback. I have been looking for a solution but found no concrete solution so far.
/workspace/course/ip/node_modules/express/lib/response.js:1007
if (err) return req.next(err);
^
TypeError: req.next is not a function
at done (/workspace/course/ip/node_modules/express/lib/response.js:1007:25)
at tryRender (/workspace/course/ip/node_modules/express/lib/application.js:642:5)
at Function.render (/workspace/course/ip/node_modules/express/lib/application.js:592:3)
at ServerResponse.render (/workspace/course/ip/node_modules/express/lib/response.js:1012:7)
at /workspace/course/ip/routes/index.js:341:13
at Array.forEach (<anonymous>)
at QueryReqWrap.callback (/workspace/course/ip/routes/index.js:340:13)
at QueryReqWrap.onresolve [as oncomplete] (dns.js:198:10)
Thank you for the report. I looked at the code and the cause (and then fix) is not obvious for me. Would you be able to provide code and steps to reproduce the error?
Ah. It is likely you are calling res.render multiple times in the same request. We can fix it so the error won't be thrown, but ultimately your code is not going to do what you're trying to do -- you can only call res.render once, when you're ready to render the response.
Let me tell you what I'm trying to do. I have an input field where a user will search for something. The form will submit the result on the same page. That's why I needed to use the first if statement. Then comes the inner code. If there's a query then it will match with the regex, and search for the result. The same logic goes in the second if statement.
Sorry to bother you mate but I am still learning nodejs and express. Could you suggest an easier way to make it work where I don't have to use res.render so many times?
What does your view file look like that you are trying to render?
hey, any solution?
I had to leave to run errands, but will be back on later to take a look. Maybe someone else can help in the meantime if you're in a hurry. Our issue tracker is not typically a quick turn around time for general help like our Gitter chat is.
Sorry. It's fine. Please take your time but check when you're back. Sorry again to bother you.
shouldn't it just be next()
You mean the error?
@azakero can you share a minimal app which reproduces this error?
Generally speaking:
next is a standalone function, not a method on the request object. You'd invoke it as:
next()
If you're just performing error handling (and not using any middleware) you could just do:
if (err) return err
But like others have mentioned, more specificity or a larger code snippet would be helpful.
@azakero is this still an issue for you ? If yes, can you please provide minimal reproducible code ?
@azakero can you share a minimal app which reproduces this error?
closing until @azakero responds
Most helpful comment
Ah. It is likely you are calling
res.rendermultiple times in the same request. We can fix it so the error won't be thrown, but ultimately your code is not going to do what you're trying to do -- you can only callres.renderonce, when you're ready to render the response.