Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Cannot read properties of undefined (reading 'nameState') After Installing @newrelic/next in Next.js Project #2880

Closed
gvatsov opened this issue Jan 15, 2025 · 7 comments

Comments

@gvatsov
Copy link

gvatsov commented Jan 15, 2025

In my Next.js project, the deployment pipeline consistently executes the command yarn add newrelic @newrelic/next -W. After a deployment on January 14, 2025, at 10:40 PM GMT+2, my application began experiencing the following error:

TypeError: Cannot read properties of undefined (reading 'nameState')
    at assignParameters (/home/production/node_modules/@newrelic/next/lib/next-server.js:133:17)
    at NextNodeServer.wrappedRenderToResponseWithComponents [as renderToResponseWithComponents] (/home/production/node_modules/@newrelic/next/lib/next-server.js:56:9)
    at NextNodeServer.renderErrorToResponseImpl (/home/production/node_modules/next/dist/server/base-server.js:1854:35)
    at async NextNodeServer.renderToResponseImpl (/home/production/node_modules/next/dist/server/base-server.js:1695:30)
    at async NextNodeServer.pipeImpl (/home/production/node_modules/next/dist/server/base-server.js:826:25)
    at async NextNodeServer.handleCatchallRenderRequest (/home/production/node_modules/next/dist/server/next-server.js:623:13)
    at async NextNodeServer.handleRequestImpl (/home/production/node_modules/next/dist/server/base-server.js:728:17)

Expected Behavior

After executing the command yarn add newrelic @newrelic/next -W and deploying the application, the Next.js project should integrate seamlessly with New Relic's monitoring tools. Specifically, the application should function normally, rendering pages and handling requests without encountering the TypeError related to nameState.

Troubleshooting or NR Diag results

a. Did you run the Troubleshooting or NR Diag tool?
No

b. Any relevant log excerpts?

TypeError: Cannot read properties of undefined (reading 'nameState')
    at assignParameters (/home/production/node_modules/@newrelic/next/lib/next-server.js:133:17)
    at NextNodeServer.wrappedRenderToResponseWithComponents [as renderToResponseWithComponents] (/home/production/node_modules/@newrelic/next/lib/next-server.js:56:9)
    at NextNodeServer.renderErrorToResponseImpl (/home/production/node_modules/next/dist/server/base-server.js:1854:35)
    at async NextNodeServer.renderToResponseImpl (/home/production/node_modules/next/dist/server/base-server.js:1695:30)
    at async NextNodeServer.pipeImpl (/home/production/node_modules/next/dist/server/base-server.js:826:25)
    at async NextNodeServer.handleCatchallRenderRequest (/home/production/node_modules/next/dist/server/next-server.js:623:13)
    at async NextNodeServer.handleRequestImpl (/home/production/node_modules/next/dist/server/base-server.js:728:17)

Note: All sensitive information has been scrubbed from the logs.

Steps to Reproduce

Execute the Command:
Run yarn add newrelic @newrelic/next -W in the deployment pipeline of the Next.js project.

Deploy the Application:
Initiate a deployment process after adding the New Relic packages.

Access the Application:
Navigate to the application's URL to interact with the deployed instance.

Observe the Error:
The application throws the following error in the console:

TypeError: Cannot read properties of undefined (reading 'nameState')
    at assignParameters (/home/production/node_modules/@newrelic/next/lib/next-server.js:133:17)
    at NextNodeServer.wrappedRenderToResponseWithComponents [as renderToResponseWithComponents] (/home/production/node_modules/@newrelic/next/lib/next-server.js:56:9)
    at NextNodeServer.renderErrorToResponseImpl (/home/production/node_modules/next/dist/server/base-server.js:1854:35)
    at async NextNodeServer.renderToResponseImpl (/home/production/node_modules/next/dist/server/base-server.js:1695:30)
    at async NextNodeServer.pipeImpl (/home/production/node_modules/next/dist/server/base-server.js:826:25)
    at async NextNodeServer.handleCatchallRenderRequest (/home/production/node_modules/next/dist/server/next-server.js:623:13)
    at async NextNodeServer.handleRequestImpl (/home/production/node_modules/next/dist/server/base-server.js:728:17)

Sample Application:
No sample application provided.

Your Environment

Browser name and version:
N/A

Node version:
20.9.0

Operating System and version:
CentOS

Other relevant software or tools:
    Next.js
    Yarn
    New Relic packages: newrelic and @newrelic/next

Additional Context

This error occurs immediately after deploying the latest version with New Relic's @newrelic/next package integrated into the Next.js project. The TypeError prevents the application from rendering pages correctly, impacting user experience and monitoring capabilities provided by New Relic.

Previous deployments with the @newrelic/next package did not exhibit this issue. Attempting to remove the New Relic packages temporarily resolves the error, indicating a direct correlation between the package installation and the encountered issue.

@workato-integration
Copy link

@jsumners-nr
Copy link
Contributor

Please review https://github.com/newrelic/node-newrelic?tab=readme-ov-file#nextjs-instrumentation. The @newrelic/next package has been integrated into the newrelic package.

@gvatsov
Copy link
Author

gvatsov commented Jan 15, 2025

I am aware of @newrelic/next. Our project is monitored for 2 years now. Since yesterday there were no issues.

The command I am using to start the process is NEXT_PUBLIC_FE_ENV=production NODE_OPTIONS='-r @newrelic/next' NEW_RELIC_HOME=~/newrelic/production pm2 start --name prod next -- start -p 3001.

What should I refer in these docs that could help me with the problem?

@mrickard
Copy link
Member

@gvatsov The @newrelic/next package has been archived since July 31, 2024, and is no longer being maintained. Since then, New Relic's instrumentation for Next.js is part of the standard newrelic agent, so we'd recommend removing the @newrelic/next package and installing the latest newrelic agent. The instructions for instrumenting with the regular agent are at the link @jsumners-nr supplied above.

@bizob2828
Copy link
Member

I'm going to close this issue. We no longer support @newrelic/next. You have to upgrade the agent(newrelic npm package) to at least v12.0.0 and you will get the Next.js instrumentation. As @jsumners-nr pointed out you have to switch your start from -r @newrelic/next to -r newrelic.

@github-project-automation github-project-automation bot moved this from Triage Needed: Unprioritized Features to Done: Issues recently completed in Node.js Engineering Board Jan 15, 2025
@birdback
Copy link

@bizob2828 is it too late to add a version 0.11.0 for @newrelic/next that has a console warning to switch to newrelic instead? I think it might save some folks time out there. A few of us were troubleshooting this thinking it was a configuration issue not a deprecation issue.

@bizob2828
Copy link
Member

@birdback we can deprecate the npm package which will give you a warning on install.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done: Issues recently completed
Development

No branches or pull requests

5 participants