Error: Cannot find the middleware module
Unanswered
Chartreux posted this in #help-forum
ChartreuxOP
I just finished setting up better auth for my next app. When I tried to test it, I got this error
Error: Cannot find the middleware module
. What could be the issue?3 Replies
ChartreuxOP
I think it's because the
runtime:"nodejs"
, since when I replaced my middleware with the default one from the next docs, the app ran normally. The better-auth docs said that this runtime is supported in next version 15.2.0 above (I'm using 15.3.x). So, why is this happening? What did I miss?@Chartreux I think it's because the `runtime:"nodejs"`, since when I replaced my middleware with the default one from the next docs, the app ran normally. The better-auth docs said that this runtime is supported in next version 15.2.0 above (I'm using 15.3.x). So, why is this happening? What did I miss?
Yes the error is most likely occured because you use the
So... if you want to use the experimental Node,js runtime in Next.js middleware you have to use the Next.js Canary
runtime:"nodejs"
in Next.js stable version not the Canary one as Next.js official docs states "Note: This feature is not yet recommended for production use. Therefore, Next.js will throw an error unless you are using the next@canary release instead of the stable release." (See: https://nextjs.org/blog/next-15-2#nodejs-middleware-experimental)So... if you want to use the experimental Node,js runtime in Next.js middleware you have to use the Next.js Canary
@lucy Yes the error is most likely occured because you use the `runtime:"nodejs"` in Next.js stable version not the Canary one as Next.js official docs states "Note: This feature is not yet recommended for production use. Therefore, Next.js will throw an error unless you are using the next@canary release instead of the stable release." (See: https://nextjs.org/blog/next-15-2#nodejs-middleware-experimental)
So... if you want to use the experimental Node,js runtime in Next.js middleware you have to use the Next.js Canary
ChartreuxOP
Alright that explains it all. I'll look for another approach then. Thanks