Closed limoragni closed 1 week ago
I don't know what the difference is. We would welcome suggestions to resolve the problem. Have you reached out to the Next team to see if they know how to resolve it?
Thanks for the reply. I haven't reached out to the NextJS team. I've been learning more about this and I think the difference is that middleware calls are restricted to the Edge Runtime only. This means the full NodeJS API is not available. I'm not sure if that's the reason for this error though, since it doesn't even get to import the module.
I found this related issue
In my view this is very limiting if you want to use newrelic with NextJS. In my case I just want to be able to add custom attributes on all requests so I can have user ids sent to newrelic, and middleware would be the right place to do that.
Unfortunately, this exceeds our knowledge of Next. We put together this example based upon their documentation and Internet sleuthing. I believe the issue is with whatever Next does to "bundle" the resources being used by the application. If you're able to get the Next team to provide an answer, we'd love to learn from it.
Description
When using the nextjs-app-router example importing the newrelic module is not working from a middleware file. The
serverComponentsExternalPackages
prevents imports from breaking when using the module from server components, but is not fixing imports from a middleware file.Steps to Reproduce
// This function can be marked
async
if usingawait
inside export function middleware(request) { newrelic.setTransactionName(request.url); return NextResponse.next(); }⨯ ./node_modules/newrelic/LICENSE Module parse failed: Unexpected token (1:40) You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
./node_modules/newrelic/LICENSE Module parse failed: Unexpected token (1:40) You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
Import trace for requested module: ./node_modules/newrelic/LICENSE ./node_modules/newrelic/ sync ^.\/.*$ ./node_modules/newrelic/index.js ⚠ ./node_modules/@newrelic/security-agent/lib/instrumentation-security/core/sec-utils.js Critical dependency: the request of a dependency is an expression