elastic / elastic/apm-agent-nodejs

Failed to start typescript app with APM agent.

Open
#3,831 1 comment 0 reactions 0 assignees View on GitHub
agent-nodejs awaiting reply community
Dominant language
JavaScript
Stars
594
Forks
244
Avg merge
1d 8h
Merged PRs (30d)
16

Description

**Describe the bug**

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

> node.jsrestapi@1.0.0 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. (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
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.