Skip to content

[Bug]: Middleware does not run with netlify-cli #1824

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

Closed
1 of 2 tasks
BrandonALittle opened this issue Dec 1, 2022 · 6 comments · Fixed by #1831
Closed
1 of 2 tasks

[Bug]: Middleware does not run with netlify-cli #1824

BrandonALittle opened this issue Dec 1, 2022 · 6 comments · Fixed by #1831
Labels
Ecosystem: Frameworks type: bug code to address defects in shipped code

Comments

@BrandonALittle
Copy link

Summary

NextJS version 13

I'm running my site locally with netlify-cli. I have middleware that runs perfectly fine with next dev, but does not even seem to exist when running netlify dev.

Steps to reproduce

  1. Create a middleware inside a NextJS v13 app
  2. Run netlify dev
  3. Load the app
  4. See that the middleware doesn't run

A link to a reproduction repository

No response

Next Runtime version

4.29.2

More information about your build

  • I am building using the CLI
  • I am building using file-based configuration (netlify.toml)

What OS are you using?

Mac OS

Your netlify.toml file

`netlify.toml`
# Paste content of your `netlify.toml` file here

Your public/_redirects file

`_redirects`
# Paste content of your `_redirects` file here

Your next.config.js file

`next.config.js`
# Paste content of your `next.config.js` file here. Check there is no private info in there.

Builds logs (or link to your logs)

Build logs
# Paste logs here

Function logs

Function logs
# Paste logs here

.next JSON files

generated .next JSON files
# Paste file contents here. Please check there isn't any private info in them
# You can either build locally, or download the deploy from Netlify by clicking the arrow next to the deploy time.
@BrandonALittle BrandonALittle added the type: bug code to address defects in shipped code label Dec 1, 2022
@ascorbic
Copy link
Contributor

ascorbic commented Dec 1, 2022

Hey. If your middleware is in src, could you try moving it into the top level? We haven't added support for middleware in the src directory yet in dev

@BrandonALittle
Copy link
Author

My middleware was in the src folder. I moved it, and it does get run, though the app doesn't load due to a this._headers.getAll is not a function error.

@ascorbic
Copy link
Contributor

ascorbic commented Dec 2, 2022

Have you manually installed the runtime? Which version is it showing as using?

@BrandonALittle
Copy link
Author

4.29.2. If manually installing the runtime means yarn add or npm install + @netlify/plugin-nextjs, then yes I have done that.

@BrandonALittle
Copy link
Author

One thing to point out is that the middleware runs when deployed via Netlify, even though the middleware on the deployed site is in the src folder. It's only locally that it doesn't run.

@BrandonALittle
Copy link
Author

Everything seems to work fine with NextJS v13.0.0 and middleware.ts at the root. It seems to be an issue with NextJS v13.0.3 & the plugin. Netlify deployments don't seem to have any issue with middleware in src and v13.0.3, though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Ecosystem: Frameworks type: bug code to address defects in shipped code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants