Search code examples
javascriptnode.jsexpressnode-modules

Node.js upgrade to 18.16.0 causing uncaughtException with [Error: Invalid argument] and no stack trace


After upgrading from Node.js 10.16.3 to 18.16.0, along with updating all dependencies (npm packages) of my projects, I'm encountering a vague uncaughtException error: [Error: Invalid argument]. This "error" has no stack trace, so it seems impossible for me to find where it's coming from. This error seems to trigger when loading the webpage, but only sometimes. Even when loading the most simple page of my app, it can trigger. It seems to trigger more frequently if I've left the page "idle" for a while. When the error occurs, the page does not load, the browser keeps "loading" but the page is never served.

This makes me think the error pops up somewhere in Express js (middleware), but I can't figure out where exactly.

In order to try to get a stack trace on this error, I've tried debugging (with the integrated node.js debugger, so using "node inspect", however this didn't help at all, I still only get the same message "[Error: Invalid argument]" without trace.

How can I troubleshoot this further? I don't know which code to share, as I can't pinpoint the exact location of the error.


Extra information: My environment (OS) is Windows 10 22H2 build 19045.2965. This is with the latest version of express (4.18.2).

The package.json:

{
  "name": "workload",
  "version": "1.0.0",
  "description": "workload app",
  "main": "app.js",
  "scripts": {
    "test": "test"
  },
  "author": "Mathieu",
  "license": "ISC",
  "dependencies": {
    "@popperjs/core": "^2.11.6",
    "body-parser": "^1.20.1",
    "bootstrap": "^5.1.3",
    "chart.js": "^4.2.0",
    "chartjs-plugin-datalabels": "^2.2.0",
    "cookie-session": "^2.0.0",
    "dotenv": "^16.0.3",
    "express": "^4.18.2",
    "jquery": "^3.6.3",
    "node-sspi": "^0.2.10",
    "pug": "^3.0.2",
    "sweetalert2": "^11.7.1",
    "tedious": "^16.1.0",
    "tedious-connection-pool2": "^2.1.0",
    "winston": "^3.8.2",
    "winston-daily-rotate-file": "^4.7.1"
  }
}

Solution

  • I managed to "fix" the issue eventually, although I don't know the root cause of the issue.

    In my case, I removed the @popperjs/core dependency as it was no longer needed. I believe it was needed as a peer dependency for another module but this was no longer the case. After removing @popperjs/core and deleting the node_modules folder and then reinstalling the dependencies, the issue seems to be fixed!