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

Middleware does not work in Next.js 13 when the /pages directory is removed #41995

Closed
1 task done
jamescmartinez opened this issue Oct 27, 2022 · 2 comments · Fixed by #43205
Closed
1 task done

Middleware does not work in Next.js 13 when the /pages directory is removed #41995

jamescmartinez opened this issue Oct 27, 2022 · 2 comments · Fixed by #43205
Assignees
Labels
area: app App directory (appDir: true) Middleware Related to Next.js Middleware

Comments

@jamescmartinez
Copy link

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 21.6.0: Mon Aug 22 20:20:05 PDT 2022; root:xnu-8020.140.49~2/RELEASE_ARM64_T8101
Binaries:
  Node: 18.10.0
  npm: 8.19.2
  Yarn: N/A
  pnpm: N/A
Relevant packages:
  next: 13.0.1-canary.0
  eslint-config-next: 13.0.0
  react: 18.2.0
  react-dom: 18.2.0

What browser are you using? (if relevant)

106.0.5249.119

How are you deploying your application? (if relevant)

n/a

Describe the Bug

Removing the pages directory prevents Next.js middleware from running.

Expected Behavior

The middleware should work with the new app directory when the pages directory does not exist.

Link to reproduction

https://github.com/jamescmartinez/nextjs13-middlware-appdir-bug

To Reproduce

  1. npm run dev to start the app
  2. open http://localhost:3000/page2 to open /page2 in your browser, noting that /page2 does not redirect to / as configured in middleware.ts
  3. stop the dev server
  4. mkdir pages to create an empty pages directory
  5. npm run dev to start the app
  6. open http://localhost:3000/page2 to open /page2 in your browser, noting that /page2 now redirects to /
@jamescmartinez jamescmartinez added the bug Issue was opened via the bug report template. label Oct 27, 2022
@jensen
Copy link

jensen commented Oct 29, 2022

I ran into this as well. Had to add a pages/.keep for deployment.

@balazsorban44 balazsorban44 added kind: bug Middleware Related to Next.js Middleware area: app App directory (appDir: true) and removed bug Issue was opened via the bug report template. labels Nov 14, 2022
ijjk pushed a commit that referenced this issue Nov 21, 2022
Fixes #41995

Closes #43144

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have a helpful link attached, see `contributing.md`

Co-authored-by: Bruno Nascimento <bruno.hn@icloud.com>
jankaifer pushed a commit to jankaifer/next.js that referenced this issue Nov 23, 2022
Fixes vercel#41995

Closes vercel#43144

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have a helpful link attached, see `contributing.md`

Co-authored-by: Bruno Nascimento <bruno.hn@icloud.com>
@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 22, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: app App directory (appDir: true) Middleware Related to Next.js Middleware
Projects
None yet
4 participants