ES Modules supportedit

If you are using ES Modules, for instance with the help of Babel, TypeScript, or the --experimental-modules flag for Node.js, all import statements are evaluated prior to calling any functions. In this case, you can’t configure the agent by passing a configuration object to the start function, as this call will happen after all of the modules have been loaded. Instead you need to import the elastic-apm-node/start module:

import apm from 'elastic-apm-node/start'

Now, configure the agent using the environment variables associated with each configuration option, or use the optional agent configuration file.

To explicitly start the agent, import elastic-apm-node and call the apm.start() method with the agent configuration object.


If you’re using TypeScript, the default import will not work unless you use the esModuleInterop compiler option. If you don’t want to switch on esModuleInterop, you instead have to import the agent like so:

import * as apm from 'elastic-apm-node/start'

If your "tsconfig.json" sets skipLibCheck false (or excludes it), then you will need to install @types/node to avoid compile errors:

npm install --save-dev @types/node