You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
Use this config '...'
Then call '....'
Then do '....'
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)
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?
Could you try changing your import line to:
import'elastic-apm-node/start.js'
I'm not familiar with the --experimental-specifier-resolution=node Node.js CLI option, so I don't know if that could be involved.
Are you able to show your "tsconfig.json" and enough of build/src/webapi/server.js to see what the actual executed JavaScript looks like?
From the stacktrace at finalizeResolution (node:internal/modules/esm/resolve:263:11) it looks like Node.js is using the ESM module loader, so I am guessing that you are using ES modules -- i.e. you have "type": "module" in your package.json. If so, you'll want to read https://www.elastic.co/guide/en/apm/agent/nodejs/current/esm.html to understand the APM agent's support for ES Modules. As a start, you'll need to use the --experimental-loader=elastic-apm-node/loader.mjs CLI option for the APM agent to be able to automatically instrument modules.
Describe the bug
Putting
import 'elastic-apm-node/start'
as the first line of startup code in Typescript app results inTo Reproduce
Steps to reproduce the behavior:
Expected behavior
Environment (please complete the following information)
How are you starting the agent? (please tick one of the boxes)
agent.start()
directly (e.g.require('elastic-apm-node').start(...)
)elastic-apm-node/start
from within the source code-r elastic-apm-node/start
Additional context
Agent config options:
Click to expand
package.json
dependencies:Click to expand
The text was updated successfully, but these errors were encountered: