Skip to content

Agent crash when defining an array of middleware to router.use #3518

@taschmidt

Description

@taschmidt

Description

When upgrading to newrelic @13.6.0, our code started breaking with the following exception:

/Users/schmidtt/w/video-api2/node_modules/newrelic/lib/subscribers/express/use.js:28
    if (fn.lazyrouter || fn.name === 'mounted_app') {
           ^
TypeError: Cannot read properties of undefined (reading 'lazyrouter')
    at ExpressUseSubscriber.handler (/Users/schmidtt/w/video-api2/node_modules/newrelic/lib/subscribers/express/use.js:28:12)
    at handler (/Users/schmidtt/w/video-api2/node_modules/newrelic/lib/subscribers/base.js:234:27)
    at node:diagnostics_channel:92:17
    at Channel.runStores (node:diagnostics_channel:177:12)
    at TracingChannel.traceSync (node:diagnostics_channel:333:18)
    at Function.use (/Users/schmidtt/w/video-api2/node_modules/express/lib/router/index.js:287:29)
    at Object.<anonymous> (/Users/schmidtt/w/video-api2/src/routes/api/index.ts:44:8)
    at Module.<anonymous> (node:internal/modules/cjs/loader:1706:14)
    at Module.wrappedCompile [as _compile] (/Users/schmidtt/w/video-api2/node_modules/@apm-js-collab/tracing-hooks/index.js:45:27)
    at Object..js (node:internal/modules/cjs/loader:1839:10)

I tracked the problem down to this change: #3424

It seems to be causing an incompatibility with some error handling middleware of ours so it's entirely possible we may need to change assumptions in there.

Expected Behavior

It shouldn't throw an exception.

Troubleshooting or NR Diag results

Steps to Reproduce

Pull down this repo and run npx tsx --env-file .env ./app.ts.

Your Environment

Node v22.21.1
MacOS 15.7.2

  • ex: Browser name and version:
  • ex: Node version:
  • ex: Operating System and version:

Additional context

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Status

Done: Issues recently completed

Relationships

None yet

Development

No branches or pull requests

Issue actions