3000 / 8888 Port Conflict with Netlify Dev and Nextauth on Localhost

Have similar issue. Investigated netlify-cli code and found solution. It helped me and hope it will help you.
Just run this script

const fs = require("fs");
const file = "node_modules/netlify-cli/src/utils/proxy.mjs";

fs.readFile(file, "utf8", function (err, data) {
  if (err) {
    return console.log(err);
  }
  var result = data.replace(
    // initial code
    `functionsServer &&
    req.method === 'POST' &&
    !isInternal(req.url) &&
    (ct.endsWith('/x-www-form-urlencoded') || ct === 'multipart/form-data')`,
    // replaced code
    `functionsServer &&
    req.method === 'POST' &&
    !isInternal(req.url) &&
    (ct.endsWith('/x-www-form-urlencoded') || ct === 'multipart/form-data') 
    && isFunction(settings.functionsPort, req.url)`
  );

  fs.writeFile(file, result, "utf8", function (err) {
    if (err) return console.log(err);
  });
});

Thanks Dmytro, a few things though Iā€™m struggling withā€¦

  1. I dont actually see a node_modules/netlify-cli when I explore in VS code under node_modules. Am I missing something?

  2. When you say run the script, where should I run that? Bit new to this!..?

  3. Do I assume correctly that you were also having the same issue on localhost, not on production? My issue is limited to localhost only, production works fine for me.

  4. Do I assume correctly such a patch would need to be manually added each time I update the related packages?

@hrishikesh does this clarify the issue from your perspective?

Hi

  1. probably you have installed this package globally. In my case I added this package as dev dependency and running this script from root of my project
  2. I think you can run it from project root if you add netlify-cli as dev dependency.
  3. Yes. I also have this issue only on localhost. On production it works fine
  4. I added postinstall hook which runs this script every time after I install packages

From my perspective thereā€™s no issue as I wasnā€™t able to reproduce this when I got your project down to a minimal reproduction. It also doesnā€™t happen in our Next-auth demo: next-runtime/demos/next-auth at main Ā· netlify/next-runtime (github.com)

@hrishikesh Iā€™ve created repo with reproducable issue (GitHub - dmytrobaida/netlify-issue-demo). Because example you sent does not cover case when we have monorepo with nextjs and functions. Also added an image with this error. Problem is that netlify cli think that last request is request to function instead next js and it returns function not found error. Hope it will help you to reproduce this issue


1 Like

We are working on some monorepo fixes to our CLI right now to support the work in Introducing the Enhanced Monorepo Experience on Netlify . I know specifically that the CLI had some struggles with next-runtime, and that we are working on fixes such as fix: use `packagePath` to compute internal functions directories by eduardoboucas Ā· Pull Request #5944 Ā· netlify/cli Ā· GitHub which weā€™ll likely release early next week. Iā€™d check back when there is a 16.0.3 release (cf Releases Ā· netlify/cli Ā· GitHub) since things may ā€œjust workā€, since you may be struggling with a known issue at the moment.

Let us know if you still see the problem after that release drops and you upgrade!

1 Like

I ended up giving up on this and moved away to Vercel as I couldnt take the pain any more with these port issues on netlify dev.

I think for such a big framework like Next.js (and given that I started using Netlify on all the content I read on how it plays nicely with Next.js and you would assume itā€™s biggest login system nextauth) itā€™s unusual to get responses from support, for a paid product to the tune of:

  • Iā€™m not a fan of Next.js so not much help (not helpful)

  • Youā€™re problem doesnt exist, because I wasnt able to replicate it.

Aside from this issue itself being annoying, the unhelpful support here put me off entirely.

Took me about 2 hours to migrate to Vercel and it all works there with their serverless functions flawlessly.

Hope others with this issue manage to solve it.