Skip to content
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

[appDir] middleware is not executed or packed when used with appDir #42686

Closed
1 task done
promer94 opened this issue Nov 9, 2022 · 5 comments
Closed
1 task done

[appDir] middleware is not executed or packed when used with appDir #42686

promer94 opened this issue Nov 9, 2022 · 5 comments
Labels
bug Issue was opened via the bug report template.

Comments

@promer94
Copy link
Contributor

promer94 commented Nov 9, 2022

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 22.1.0: Sun Oct 9 20:15:09 PDT 2022; root:xnu-8792.41.9~2/RELEASE_ARM64_T6000
Binaries:
Node: 18.12.0
npm: 8.19.2
Yarn: 1.23.0-20220130.1630
pnpm: 7.14.0
Relevant packages:
next: 13.0.3-canary.2
eslint-config-next: 12.2.0
react: 18.2.0
react-dom: 18.2.0

Describe the Bug

middleware is not executed or packed when used with app dir

Expected Behavior

After enable appDIr, middleware should still work.

const nextConfig = {
  reactStrictMode: true,
  experimental: {
    appDir: true,
  },
}

Link to reproduction - Issues with a link to complete (but minimal) reproduction code will be addressed faster

https://github.com/promer94/next-middleware-app

To Reproduce

  • start app
pnpm dev

Screenshot 2022-11-09 at 22 11 55

The Set-Cookie header is missing from reponse header and the console.log did not execute

@promer94 promer94 added the bug Issue was opened via the bug report template. label Nov 9, 2022
@promer94 promer94 closed this as completed Nov 9, 2022
@promer94 promer94 changed the title [appDIr] middleware is not executed or packed when used with app dir [appDir] middleware is not executed or packed when used with appDir Nov 9, 2022
@promer94 promer94 reopened this Nov 9, 2022
@AdhamMoussa

This comment was marked as off-topic.

@deviantpixel
Copy link

I can confirm this issue as well. It is a bit difficult with new vs legacy documentation. I have tried the following based on various documentation sources:

  • Added allowMiddlewareResponseBody: true to the experimental next.config.js config file
  • Tried moving the middleware.ts file outside the app directory
  • Tried renaming the file to middleware.js just to ensure it's not a TS issue

All of these still result in the middleware function not being utilized. I plan to switch to not use the appDir option for now. Let me know if I can help provide additional information.

@matthewbean
Copy link

Same here, there is a workaround that I found to work though. Create a pages directory with an empty “.gitkeep” file in it. Middleware started working after that.

@balazsorban44
Copy link
Member

Duplicate of #41995

@github-actions
Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 14, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template.
Projects
None yet
5 participants