Netlify CLI has terminated unexpectedly - MongoServerError: bad auth : Authentication failed

Whenever I run netlify dev in my local project directory, the netlify cli always terminates with the following error message.
Error Message

PS C:\Users\sanja\Desktop\Coding\WEB DEV\Projects\Employee-Data> netlify dev
◈ Netlify Dev ◈
◈ Ignored general context env var: LANG (defined in process)
◈ Setting up local development server
◈ Starting Netlify Dev with Create React App

> employee-data@1.0.0 start
> react-scripts start

(node:20172) [DEP_WEBPACK_DEV_SERVER_ON_AFTER_SETUP_MIDDLEWARE] DeprecationWarning: 'onAfterSetupMiddleware' option is deprecated. Please use the 'setupMiddlewares' option.
(Use `node --trace-deprecation ...` to show where the warning was created)
(node:20172) [DEP_WEBPACK_DEV_SERVER_ON_BEFORE_SETUP_MIDDLEWARE] DeprecationWarning: 'onBeforeSetupMiddleware' option is deprecated. Please use the 'setupMiddlewares' option.
Starting the development server...

Compiled successfully!

You can now view employee-data in the browser.

  Local:            http://localhost:3000
  On Your Network:  http://192.168.1.11:3000

Note that the development build is not optimized.
To create a production build, use npm run build.

webpack compiled successfully
✔ Waiting for framework port 3000. This can be configured using the 'targetPort' property in the netlify.toml
◈ Loaded function model
◈ Loaded function fetch
◈ Loaded function submit
◈ Loaded function delete

   ┌─────────────────────────────────────────────────┐
   │                                                 │
   │   ◈ Server now ready on http://localhost:8888   │
   │                                                 │
   └─────────────────────────────────────────────────┘

⠙ Setting up the Edge Functions environment. This may take a couple of minutes.Request from ::1: GET /.netlify/functions/fetch
⠼ Setting up the Edge Functions environment. This may take a couple of minutes.
 »   Error: Netlify CLI has terminated unexpectedly
This is a problem with the Netlify CLI, not with your application.
If you recently updated the CLI, consider reverting to an older version by running:

npm install -g netlify-cli@VERSION

You can use any version from https://ntl.fyi/cli-versions.

Please report this problem at https://ntl.fyi/cli-error including the error details below.

⠏ Setting up the Edge Functions environment. This may take a couple of minutes.MongoServerError: bad auth : Authentication failed.
    at Connection.onMessage (C:\Users\sanja\Desktop\Coding\WEB DEV\Projects\Employee-Data\netlify\functions\node_modules\mongodb\lib\cmap\connection.js:202:26)
    at MessageStream.<anonymous> (C:\Users\sanja\Desktop\Coding\WEB DEV\Projects\Employee-Data\netlify\functions\node_modules\mongodb\lib\cmap\connection.js:61:60)
    at MessageStream.emit (node:events:513:28)
    at MessageStream.emit (node:domain:489:12)
    at processIncomingData (C:\Users\sanja\Desktop\Coding\WEB DEV\Projects\Employee-Data\netlify\functions\node_modules\mongodb\lib\cmap\message_stream.js:124:16)
    at MessageStream._write (C:\Users\sanja\Desktop\Coding\WEB DEV\Projects\Employee-Data\netlify\functions\node_modules\mongodb\lib\cmap\message_stream.js:33:9)
    at writeOrBuffer (node:internal/streams/writable:392:12)
    at _write (node:internal/streams/writable:333:10)
    at Writable.write (node:internal/streams/writable:337:10)
    at TLSSocket.ondata (node:internal/streams/readable:766:22)

  System:
    OS: Windows 10 10.0.22621
    CPU: (8) x64 11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz
  Binaries:
    Node: 18.13.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.19 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 8.19.3 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Chromium (120.0.2210.61)

I don’t understand why it shows bad auth when my mongodb username and password are correctly stored in a .env file in the netlify/functions directory of my project. (I can assure you they are correct and stored with the proper variable name)

Also below is the fetch function mentioned in the error message:

const mongoose = require('mongoose');
const Profile = require('./model');

exports.handler = async function (event, context) {
  const username = process.env.MONGODB_USERNAME;
  const password = process.env.MONGODB_PASSWORD;
  mongoose.connect(`mongodb+srv://${username}:${password}@cluster0.********.mongodb.net/`);
  const { httpMethod } = event;

  if (httpMethod !== 'GET') {
    return {
      statusCode: 405,
      body: 'Method Not Allowed',
    };
  }

  try {
    const employees = await Profile.find();

    return {
      statusCode: 200,
      headers: {
        'Content-Type': 'application/json',
      },
      body: JSON.stringify(employees),
    };
  } catch (error) {
    console.error('Error retrieving all employee data:', error);

    return {
      statusCode: 500,
      body: `⚠️⚠️⚠️ ALERT!! ERROR IN RETRIEVING ALL EMPLOYEE DATA: ${error}`,
    };
  }
};

Git Repo
Please help me rectify this issue.

Try running your project in WSL. Then you can see the complete error message which is not visible in Windows.