# Nodejs APM - Can't resolve 'async\_hooks'

**URL:** <https://discuss.elastic.co/t/nodejs-apm-cant-resolve-async-hooks/302644>\
**Category:** APM\
**Tags:** nodejs\
**Created:** [April 18, 2022, 8:57pm UTC](https://discuss.elastic.co/t/nodejs-apm-cant-resolve-async-hooks/302644 "2022-04-18T20:57:36Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jsoule6](https://avatars.discourse-cdn.com/v4/letter/j/e56c9b/32.png) [@jsoule6](https://discuss.elastic.co/u/jsoule6)\
**Post date:** [April 18, 2022, 8:57pm UTC](https://discuss.elastic.co/t/nodejs-apm-cant-resolve-async-hooks/302644/1 "2022-04-18T20:57:36Z")

</div>

Hello,

We are trying to use APM for our React nodejs app.

We have added the dependency in our package.json to install the elastic-apm-node module:

`"elastic-apm-node": "^3.31.0"`

And then we added the below line in our index.js after our imports, but before the start of any other processes:

`var apm = require('elastic-apm-node').start()`

We get the following error messages we try to run an install of our project:

```auto
./node_modules/elastic-apm-node/lib/instrumentation/span.js
Module not found: Can't resolve 'async_hooks' in '\node_modules\elastic-apm-node\lib\instrumentation'

```

Any ideas what we are doing wrong?

Thanks!

---

<div class="post-metadata">

**Author:** ![alanstorm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alanstorm/32/77134_2.png) [@alanstorm](https://discuss.elastic.co/u/alanstorm)\
**Post date:** [April 18, 2022, 11:13pm UTC](https://discuss.elastic.co/t/nodejs-apm-cant-resolve-async-hooks/302644/2 "2022-04-18T23:13:36Z")

</div>

Hey Joseph, nice to meet you.

The most common reason for the error you're seeing

> ./node\_modules/elastic-apm-node/lib/instrumentation/span.js  
> Module not found: Can't resolve 'async\_hooks' in '\node\_modules\elastic-apm-node\lib\instrumentation'

is a _frontend_ build system trying to resolve the built-in Node.js `async_hooks` module. You didn't mention it, but I'm guessing that `index.js` is your root React component?

The Node.js agent will allow you to monitor _backend_ Node.js services and Node.js CLI applications. It will not allow you to monitor a React application, or any other frontend framework. To monitor a React application, you'll want to use the "Real User Monitoring JavaScript agent" (sometimes called the browser agent).

> **[Supported Technologies | APM Real User Monitoring JavaScript Agent Reference...](https://www.elastic.co/guide/en/apm/agent/rum-js/current/supported-technologies.html#frameworks)**

So, if what I've said above about your `index.js` file is correct, the steps I'd take to fix your problem are

1. Remove the Node Agent from your `index.js` file
2. Add [the RUM React integration](https://www.elastic.co/guide/en/apm/agent/rum-js/current/react-integration.html) to your project
3. If you have a separate backend service written in Node.js, add the Node.js agent to its initial file

Does that make sense/get your moving in the right direction?

---

<div class="post-metadata">

**Author:** ![jsoule6](https://avatars.discourse-cdn.com/v4/letter/j/e56c9b/32.png) [@jsoule6](https://discuss.elastic.co/u/jsoule6)\
**Post date:** [April 19, 2022, 1:00pm UTC](https://discuss.elastic.co/t/nodejs-apm-cant-resolve-async-hooks/302644/3 "2022-04-19T13:00:25Z")

</div>

Hi Alan,

That makes perfect sense, thank you!

I do have one other question now that we will be going the RUM route. Is there auto-instrumentation if we just add the agent to our project by following the "Using Bundlers" section in the following section:

> **[Install the Agent | APM Real User Monitoring JavaScript Agent Reference \[5.x\]...](https://www.elastic.co/guide/en/apm/agent/rum-js/current/install-the-agent.html)**

Or will we not get any useful metrics unless we integrate with React using the Integration instructions that you posted? We are trying to limit the code changes as much as possible. We loved the way that the java agents require no code change as we like to keep APM separate from the code as much as we can.

Thank you!

---

<div class="post-metadata">

**Author:** ![Alberto\_Delgado](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alberto_delgado/32/98488_2.png) [@Alberto\_Delgado](https://discuss.elastic.co/u/Alberto_Delgado)\
**Post date:** [April 19, 2022, 2:56pm UTC](https://discuss.elastic.co/t/nodejs-apm-cant-resolve-async-hooks/302644/4 "2022-04-19T14:56:29Z")

</div>

Hi @jsoule6,

Thanks for your interest in RUM.

The RUM agent provides with auto instrumentation for:

1. [page load metrics](https://www.elastic.co/guide/en/apm/agent/rum-js/current/supported-technologies.html#page-load-metrics)
2. [User interactions](https://www.elastic.co/guide/en/apm/agent/rum-js/current/supported-technologies.html#user-interactions) (clicks)
3. [Route changes](https://www.elastic.co/guide/en/apm/agent/rum-js/current/supported-technologies.html#spa)
4. Fetch and xhr requests in order to create http-request transactions
5. Errors are also automatically observed

This last [link](https://www.elastic.co/guide/en/apm/agent/rum-js/current/supported-technologies.html#spa) gives you a overall view of available instrumentations. There you will also see that you can disable them in case you need it.

Does that help you?

Thanks,  
Alberto

---

<div class="post-metadata">

**Author:** ![jsoule6](https://avatars.discourse-cdn.com/v4/letter/j/e56c9b/32.png) [@jsoule6](https://discuss.elastic.co/u/jsoule6)\
**Post date:** [April 19, 2022, 5:54pm UTC](https://discuss.elastic.co/t/nodejs-apm-cant-resolve-async-hooks/302644/5 "2022-04-19T17:54:32Z")

</div>

Thank you @Alberto_Delgado. We are going to give this a try without customizing any routes and see how it goes.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [May 10, 2022, 1:55pm UTC](https://discuss.elastic.co/t/nodejs-apm-cant-resolve-async-hooks/302644/6 "2022-05-10T13:55:15Z")

</div>

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.
