middleware.ts problems
Unanswered
Erythrina gall wasp posted this in #help-forum
Erythrina gall waspOP
Hello, i'm currently working on a project.
I'm using nextjs13 with app directory, using the src folder.
I'm working in collaboration with one of my friend.
On my side, the middleware.ts doesn't apply when the file is in the root of the project (outside of the src folder) but works when it is inside the source folder.
But for my friend, this is the opposite, it only works when it is on the root of the project and not in the src.
I would like to know where it comes from, since we both have the same configuration, thanks for your answers !
I'm using nextjs13 with app directory, using the src folder.
I'm working in collaboration with one of my friend.
On my side, the middleware.ts doesn't apply when the file is in the root of the project (outside of the src folder) but works when it is inside the source folder.
But for my friend, this is the opposite, it only works when it is on the root of the project and not in the src.
I would like to know where it comes from, since we both have the same configuration, thanks for your answers !
51 Replies
middleware should be in root
@@ts-ignore middleware should be in root
Erythrina gall waspOP
i have tried in there, but only had it work in root 😠(maybe i haven't done it correctly)
I don't use src but when tried it never worked
@riský i have tried in there, but only had it work in root 😠(maybe i haven't done it correctly)
Erythrina gall waspOP
it does for my friend too, but for me it only work in the src
so does it work if this file structure:
or in
* /next.config.ts
* /middleware.ts
* src/
* /app
* /page.tsx
* /layout.tsxor in
* /next.config.ts
* src/
* /middleware.ts
* /app
* /page.tsx
* /layout.tsxErythrina gall waspOP
For my friend : It does ONLY work on the first exemple
but for me: ONLY in the second exemple
that's what's weird about it
but does your friend have it work in seccond?
Erythrina gall waspOP
nope
ahhhh
and you are both using latest version of nextjs
Erythrina gall waspOP
Both same project, same version, 13.4.19
docker etc
same shit
lol what?????
Erythrina gall waspOP
yessir
and same OS?
@riský and same OS?
docker so yes ig
docker i thought can be different OSes...
and you are very sure that it is inside the src for your friend...
Erythrina gall waspOP
Yes he is just next to me
lol
if you're getting this weird behaviour just create a symlink


Erythrina gall waspOP
that's some black magic right there
tbh id say importing and exporting same contents is better than symlinking only because it shows that it is being copied, but maybe it could be better because you are doing it correctly and just fixing for incorect
also, you both have reset next cache (removed .next folder) and tried running again?
Erythrina gall waspOP
we tried everything 

...something is sus here...
ig you should do some sketchy simlinking then (or import and export the config from other middlewire)
or just not use src folder
Erythrina gall waspOP
Problem solved, have 1 middleware in root and 1 in src, both same content

temporary fix, but good enough for today 🙂
Erythrina gall waspOP
I guess yeah
also how big is the middlewire file anyway
Erythrina gall waspOP
50 lines
40 replies 💀
Erythrina gall waspOP
that's some i18n shit
have fun when changing the file... (make big comment saying to not forget about other one)
Erythrina gall waspOP
yup ahah
someone just asked if you are using the same node versions
[Node versions?](https://discord.com/channels/752553802359505017/766433464055496744/1153313953087246376)
Erythrina gall waspOP
yes we are
and you don't have any other middlewire files (before you made the 2) - like .js instead of ts (im sure you are smart enought to test that tho)
Erythrina gall waspOP
Nope, I checked everything ahahah
But yeah good you asked lol
and this is for dev mode and/or prod mode (next build and next start)?
@Erythrina gall wasp and last thing: try using the [basic template](https://github.com/vercel/next.js/tree/canary/examples/reproduction-template), and add a basic middlewire file and test if the error happens on your code or in the system