Title: [nextjs] Placing middleware.ts in src directory causes middleware to be ignored · Issue #8845 · getsentry/sentry-javascript · GitHub
Open Graph Title: [nextjs] Placing middleware.ts in src directory causes middleware to be ignored · Issue #8845 · getsentry/sentry-javascript
X Title: [nextjs] Placing middleware.ts in src directory causes middleware to be ignored · Issue #8845 · getsentry/sentry-javascript
Description: Is there an existing issue for this? I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues I have reviewed the documentation https://docs.sentry.io/ I am using the latest SDK release https://github.com/...
Open Graph Description: Is there an existing issue for this? I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues I have reviewed the documentation https://docs.sentry.io/ I am using th...
X Description: Is there an existing issue for this? I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues I have reviewed the documentation https://docs.sentry.io/ I am using th...
Opengraph URL: https://github.com/getsentry/sentry-javascript/issues/8845
X: @github
Domain: github.com
IPv4 address: 140.82.114.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[nextjs] Placing middleware.ts in src directory causes middleware to be ignored","articleBody":"### Is there an existing issue for this?\n\n- [X] I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues\n- [X] I have reviewed the documentation https://docs.sentry.io/\n- [X] I am using the latest SDK release https://github.com/getsentry/sentry-javascript/releases\n\n### How do you use Sentry?\n\nSentry Saas (sentry.io)\n\n### Which SDK are you using?\n\n@sentry/nextjs\n\n### SDK Version\n\n7.64.0\n\n### Framework Version\n\n7.64.0\n\n### Link to Sentry event\n\n_No response_\n\n### SDK Setup\n\n```\r\nSentry.init({\r\n dsn: \"DSN\",\r\n tracesSampleRate: 1,\r\n debug: false,\r\n});\r\n```\n\n### Steps to Reproduce\n\nBasically, middleware gets bypassed/ignored when the middleware.(ts|js) file is placed in the `src` folder, something that is supported [according to Next.js documentation](https://nextjs.org/docs/app/building-your-application/routing/middleware#convention).\r\n\r\n1. `npx create-next-app --example reproduction-template reproduction-app`\r\n2. `cd reproduction-app`\r\n3. `npx @sentry/wizard -i nextjs`\r\n4. `mkdir src`\r\n5. `mv app src/`\r\n6. `touch src/middleware.ts`\r\n7. Middleware contents:\r\n ```\r\nexport function middleware(request) {\r\n throw new Error(\"This never runs\");\r\n}\r\n```\r\n8. `mkdir -p src/app/api/test`\r\n9. `touch src/app/api/test/route.ts`\r\n10. src/app/api/test/route.ts contents:\r\n```\r\nimport { NextResponse } from \"next/server\";\r\n\r\nexport function GET() {\r\n return NextResponse.json(\r\n {\r\n success: \"middleware not called\",\r\n },\r\n { status: 200 }\r\n );\r\n}\r\n```\r\n11. `yarn build && yarn start`\r\n12. `curl http://localhost:3000/api/test`\n\n### Expected Result\n\nThe curl request never reaches the `src/api/test/route.ts` route due to middleware throwing an error.\r\nAccording to [Next.js's documentation on middleware conventions](https://nextjs.org/docs/app/building-your-application/routing/middleware#convention) the middleware.ts file should be able to be placed in both the root and in the src directory.\n\n### Actual Result\n\nThe curl request reaches the `src/api/test/route.ts` route.","author":{"url":"https://github.com/jskovman","@type":"Person","name":"jskovman"},"datePublished":"2023-08-18T15:13:27Z","url":"https://github.com/getsentry/sentry-javascript/issues/8845"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:a94c4e73-b245-b973-8c35-023c5f1fd662 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E896:2B63A2:3E2048:55216C:6B046E2A |
| html-safe-nonce | 3e45d882b42e8c49d5d72ae1d4dff56a0a751b72e90a513eea7660c07358079c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFODk2OjJCNjNBMjozRTIwNDg6NTUyMTZDOjZCMDQ2RTJBIiwidmlzaXRvcl9pZCI6IjQzNjE0MDI5NjQzMjY1MTAxMjIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | eaefe0208d4adc500de5aaf8132d97377ac77ee8d106e89edee6a4f2cd370144 |
| hovercard-subject-tag | issue:1856888606 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/getsentry/sentry-javascript/8845/issue_layout |
| twitter:image | https://opengraph.githubassets.com/69809f0d922f9fe9afc9b687dfc9af31b2a7cb4b43148780b763b9b1a890a29a/getsentry/sentry-javascript/issues/8845 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/69809f0d922f9fe9afc9b687dfc9af31b2a7cb4b43148780b763b9b1a890a29a/getsentry/sentry-javascript/issues/8845 |
| og:image:alt | Is there an existing issue for this? I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues I have reviewed the documentation https://docs.sentry.io/ I am using th... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | jskovman |
| hostname | github.com |
| expected-hostname | github.com |
| None | ae8802492f12d3ba4f6b0d814054e617a2a5616b6327bf8555c10cd5b0dc2a6f |
| turbo-cache-control | no-preview |
| go-import | github.com/getsentry/sentry-javascript git https://github.com/getsentry/sentry-javascript.git |
| octolytics-dimension-user_id | 1396951 |
| octolytics-dimension-user_login | getsentry |
| octolytics-dimension-repository_id | 3328572 |
| octolytics-dimension-repository_nwo | getsentry/sentry-javascript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 3328572 |
| octolytics-dimension-repository_network_root_nwo | getsentry/sentry-javascript |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | cfb5f24c6e01d85f70804652a5107e5cac03a161 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width