Skip to content

Failed to start typescript app with APM agent. #3831

Open
@khteh

Description

@khteh

Describe the bug

Putting import 'elastic-apm-node/start' as the first line of startup code in Typescript app results in

$ n start

> [email protected] start
> export NODE_ENV=development&& node --experimental-specifier-resolution=node build/src/webapi/server.js

node:internal/process/esm_loader:34
      internalBinding('errors').triggerUncaughtException(
                                ^

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/usr/src/Node.JSRestAPI/node_modules/elastic-apm-node/start' imported from /usr/src/Node.JSRestAPI/build/src/webapi/server.js
Did you mean to import elastic-apm-node/start.js?
    at finalizeResolution (node:internal/modules/esm/resolve:263:11)
    at moduleResolve (node:internal/modules/esm/resolve:908:10)
    at defaultResolve (node:internal/modules/esm/resolve:1121:11)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:396:12)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:365:25)
    at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:240:38)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:85:39)
    at link (node:internal/modules/esm/module_job:84:36) {
  code: 'ERR_MODULE_NOT_FOUND',
  url: 'file:///usr/src/Node.JSRestAPI/node_modules/elastic-apm-node/start'
}

Node.js v21.5.0

To Reproduce

Steps to reproduce the behavior:

  1. Use this config '...'
  2. Then call '....'
  3. Then do '....'
  4. See error

Expected behavior

Environment (please complete the following information)

  • OS: [e.g. Linux] Ubuntu 23.10
  • Node.js version: 21.5.0
  • APM Server version:
  • Agent version: 4.3.0

How are you starting the agent? (please tick one of the boxes)

  • Calling agent.start() directly (e.g. require('elastic-apm-node').start(...))
  • [ x] Requiring elastic-apm-node/start from within the source code
  • Starting node with -r elastic-apm-node/start

Additional context

Agent config options:

Click to expand
replace this line with your agent config options

package.json dependencies:

Click to expand
replace this line with your dependencies section from package.json

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions