I've been getting this error more recently and it's been bugging me for a while, I've tried the following:
Reinstalled node_modules
Deleted .next folder
Here is the full error
C:\Users\**\Documents\GitHub\**\****\node_modules\next-connect\dist\index.cjs:1
TypeError: Cannot read property 'routes' of undefined
at mount (C:\Users\**\Documents\GitHub\**\****\node_modules\next-connect\dist\index.cjs:6:27)
at Array.map (<anonymous>)
at Function.use (C:\Users\**\Documents\GitHub\**\****\node_modules\next-connect\dist\index.cjs:43:23)
at Function.use (C:\Users\**\Documents\GitHub\**\****\node_modules\next-connect\dist\index.cjs:29:47)
at Object../pages/api/user.js (C:\Users\**\Documents\GitHub\**\****\.next\server\pages_api_user_js-server_lib_passport_js-server_middleware_auth_js.js:23:9)
at __webpack_require__ (C:\Users\**\Documents\GitHub\**\****\.next\server\webpack-runtime.js:25:42)
at Object../server/lib/passport.js (C:\Users\**\Documents\GitHub\**\****\.next\server\pages_api_user_js-server_lib_passport_js-server_middleware_auth_js.js:245:73)
at __webpack_require__ (C:\Users\**\Documents\GitHub\**\****\.next\server\webpack-runtime.js:25:42)
at Object../server/middleware/auth.js (C:\Users\**\Documents\GitHub\**\****\.next\server\pages_api_user_js-server_lib_passport_js-server_middleware_auth_js.js:354:71)
at __webpack_require__ (C:\Users\**\Documents\GitHub\**\****\.next\server\webpack-runtime.js:25:42)
at Object../pages/dashboard.js (C:\Users\**\Documents\GitHub\**\****\.next\server\pages\dashboard.js:2865:81)
at __webpack_require__ (C:\Users\**\Documents\GitHub\**\****\.next\server\webpack-runtime.js:25:42)
at __webpack_exec__ (C:\Users\**\Documents\GitHub\**\****\.next\server\pages\dashboard.js:3251:52)
at C:\Users\**\Documents\GitHub\**\****\.next\server\pages\dashboard.js:3252:358
at Function.__webpack_require__.X (C:\Users\**\Documents\GitHub\**\****\.next\server\webpack-runtime.js:108:21)
at C:\Users\**\Documents\GitHub\**\****\.next\server\pages\dashboard.js:3252:47
Here is the file that is causing the error:
import nextConnect from 'next-connect';
import auth from '../../server/middleware/auth';
const handler = nextConnect();
handler.use(auth).post(async (req, res) => {
// Creates user and logs them in
req.login(cleanUser(newUser), (err) => {
if (err) throw err;
res.status(201).json({
success: true,
user: cleanUser(newUser),
message: 'Successfully signed up, you were automatically logged in!',
});
});
});
export default handler;
I've been getting this error more recently and it's been bugging me for a while, I've tried the following:
Here is the full error
Here is the file that is causing the error:
Here is the "auth" file:
Any help I would appreciate, thanks.