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

"Can't resolve 'elastic-apm-node'" error when used in a Next.js app #187

Closed
petter opened this issue May 10, 2024 · 2 comments
Closed

"Can't resolve 'elastic-apm-node'" error when used in a Next.js app #187

petter opened this issue May 10, 2024 · 2 comments

Comments

@petter
Copy link

petter commented May 10, 2024

I'm trying to use @elastic/ecs-pino-format in my Next.js app, and it's working mostly fine. However, whenever a logger instance is created I get the following error in my console:

 ⚠ ../../node_modules/@elastic/ecs-pino-format/index.js
Module not found: Can't resolve 'elastic-apm-node' in '/Users/petter/workspace/domstol/lovisa_core/node_modules/@elastic/ecs-pino-format'

Import trace for requested module:
../../node_modules/@elastic/ecs-pino-format/index.js
../../shared_library/frontend/logging/src/server.ts
../../shared_library/frontend/feature-toggles/src/backend.ts
../../shared_library/frontend/feature-toggles/src/index.ts
./src/app/layout.tsx

This seems to only happen during development in a Next.js app not using turbopack, so it's not a huge issue. Is there any way to stop these log messages?

Also seems to happen with the @elastic/ecs-winston-format package.

Reproduction

CodeSandbox

@petter
Copy link
Author

petter commented May 10, 2024

I'm guessing it comes from attempting to requiring the package during instantiation. Would a require.resolve() check be a workaround for this? 🤔

@petter
Copy link
Author

petter commented May 13, 2024

I've looked some more into this. It seems that whenever there is a require somewhere in a file, webpack will try to resolve it. Even if the require expression is never run. Because of this there doesn't seem to be a simple fix for this issue.

Since this is only an issue in Next.js with webpack (AFAIK) it isn't a big deal for us at least since turbopack will soon be the new standard anyways.

@petter petter closed this as completed May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant