elastic / ecs-logging-nodejs

https://www.elastic.co/guide/en/ecs-logging/nodejs/master/intro.html
Apache License 2.0
68 stars 39 forks source link

Can't resolve 'elastic-apm-node' #189

Open aniketbiprojit opened 4 months ago

aniketbiprojit commented 4 months ago

⚠ ./node_modules/.pnpm/@elastic+ecs-winston-format@1.5.3/node_modules/@elastic/ecs-winston-format/index.js Module not found: Can't resolve 'elastic-apm-node' in '.pnpm/@elastic+ecs-winston-format@1.5.3/node_modules/@elastic/ecs-winston-format'

Should I need to install this? I am not using elastic-apm-node anywhere.

This happens when I trying to integrate with Nextjs. Runs fine otherwise.

export const logger = winston.createLogger({
  format: ecsFormat(),
  transports: [
    new winston.transports.Console(),
    new winston.transports.File({ filename: `${outLogPath}/out-json.log` }),
  ],
});

This seems to be silently ignored in js file but I still get this error logged in NextJS logs.

Any ideas on how to suppress this error?

image
trentm commented 3 months ago

@aniketbiprojit Sorry about the delay in responding!

As you have found the usage of elastic-apm-node in the @elastic/ecs-winston-format module is meant to be silent if it cannot find that module.

You say you are using Next.js. That often means that a bundler is being used to produce a single .js file (or set of .js files) that are being run, instead of using the tree of files under ./node_modules/.... Do you know if that is the case for you?

Can you show the actual .js code that is doing that elasticApm = require('elastic-apm-node') call? Is it actually ./node_modules/.pnpm/https://github.com/elastic+ecs-winston-format@1.5.3/node_modules/@elastic/ecs-winston-format/index.js or is that a source-map'ped point from a large bundle JS file?

Are you getting that Module not found: Can't resolve 'elastic-apm-node' at build/compile time? Or at runtime? From your comment "but I still get this error logged in NextJS logs." ... I'm guessing this is at runtime.

If this is in a bundle, I'd love to see that bundle file. It may be that you cannot share the whole thing, if it has proprietary code in it, however.

aniketbiprojit commented 3 months ago

Hi. I kind of gave up on the package and wrote my own formatter for the same.

So the error was at compile time (dev and build processes). Never reached runtime.

aniketbiprojit commented 3 months ago

Also when I installed elastic-apm-node it was throwing the same error for missing deps which are imported in elastic-apm-node.