NodeJs
async_hooks
module error
troubleshooting
JavaScript

Error Cannot find module 'async_hooks' in NodeJs

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

Introduction

async_hooks is a built-in Node.js core module, so if Node says it cannot find it, the problem is usually not a missing npm package. It is usually one of these: the Node runtime is too old, the code is running outside real Node, or the toolchain is resolving modules in the wrong environment.

What async_hooks Is

async_hooks lets Node track asynchronous resource lifecycles. Libraries use it for request context propagation, tracing, and instrumentation.

A normal import looks like this:

javascript
const asyncHooks = require("async_hooks");

or in ESM:

javascript
import asyncHooks from "node:async_hooks";

Because it is a core module, you should not install it from npm.

Check the Node Version First

The simplest cause is an old runtime. async_hooks was introduced in Node 8, so very old Node versions will fail immediately.

bash
node -v

If the runtime is old, upgrade Node and rerun the program. In modern projects, the real fix is usually not "make this work on Node 6." It is "run the supported Node version for the application."

Make Sure the Code Is Really Running in Node

Another common issue is trying to use a Node core module in an environment that is not actually Node, such as:

  • browser bundles
  • frontend build output
  • edge or serverless runtimes with partial Node compatibility
  • test environments configured to emulate the browser

If the code is bundled for the browser, async_hooks is simply the wrong API. No amount of npm installation will turn it into a browser feature.

Prefer the Explicit node: Prefix in Newer Code

In modern Node, importing core modules with the node: prefix makes intent clearer:

javascript
import asyncHooks from "node:async_hooks";

This does not fix an old runtime, but it reduces ambiguity between built-in modules and package names. It also makes bundler errors easier to interpret.

Transitive Dependencies Can Trigger the Error

Sometimes your own code never imports async_hooks, but a dependency does. In that case, the fix may be:

  • upgrade Node
  • upgrade the dependency
  • stop bundling server-side code into a non-Node target

The key step is to identify who is importing the module. The stack trace or bundler output usually points to the package doing it.

Local Machine Versus CI Differences

This error also appears when local development uses one Node version and CI, Docker, or production uses another. The code may work perfectly on your laptop and then fail in deployment because the runtime image is older or built for a different target.

That is why checking node -v in every environment matters, not just on the machine where the bug was reported first.

Do Not Try npm install async_hooks

This is a classic wrong turn. Since async_hooks is built into Node, npm installation is not the solution. If that command appears to help, it usually means the environment was misconfigured in a more serious way.

The correct mental model is "fix the runtime or target," not "add the package."

Common Pitfalls

  • Treating async_hooks like a third-party npm dependency.
  • Running code that expects Node core modules inside a browser-targeted build.
  • Ignoring the actual Node version used in production or CI.
  • Looking only at your own imports when the module comes from a dependency.
  • Mixing CommonJS, ESM, and bundler settings without checking the real runtime target.

Summary

  • 'async_hooks is a Node core module, not an npm package.'
  • The most common causes are an old Node version or a non-Node runtime target.
  • Check node -v before changing code.
  • In newer code, node:async_hooks makes the core-module import explicit.
  • If a dependency imports it, the fix may be in the dependency version or runtime environment rather than in your own source.

Related reading
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

All Rights Reserved.