Skip to content

Agent undefined error in next.js page router in custom _document after upgrading to from 13.2.1 -> 13.4.0 #3479

@EvertLagerberg

Description

@EvertLagerberg

Description

We have this setup in a next.js 14 page router application:
https://github.com/newrelic/newrelic-node-examples/blob/9415503f3bd78fa5d87a7214596d51c946199474/nextjs/nextjs-legacy/pages/_document.jsx

    if (newrelic.agent.collector.isConnected() === false) {
      await new Promise((resolve) => {
        newrelic.agent.on("connected", resolve)
      })
    }

After upgrading from version 13.2.1 to 13.4.0 we started getting this error
TypeError: Cannot read properties of undefined (reading 'collector') at....

Seems like the new relic agent is undefined?

Expected Behavior

We expect to be able to check if the agent is connected or not and according to documentation we should not need any null checks

Steps to Reproduce

Set up for next.js with page router according to examples.

Your Environment

Node version: 22
Version: between 13.2.1 and 13.4.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Done: Issues recently completed

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions