published fresh until

Node.js: Cannot find module 'express'

Summary For a CommonJS Node app, locate the importing file and install Express in its owning package. Separate an absent install from a wrong package root or omitted runtime dependency. Diagnose from the caller with require.resolve

Not for Bun missing-module resolution; see bun-cannot-find-module-resolver-paths-isolated-installs

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Error: Cannot find module 'express' The CommonJS loader cannot resolve Express from the file that requires it. Do first: run node -p "require.resolve('express', { paths: ['./src'] })" from the app root, replacing ./src with the importing file's directory from the Require stack. Evidence: Node documents caller-based resolution and public reports show misplaced installs; a resolved filename is the first project-level check. Not for: Bun missing-module resolution; see bun-cannot-find-module-resolver-paths-isolated-installs

As of November 2026, these branches target Node.js 22.23.4 with npm 11.21.2. Their dated baselines are the October 21 Node release and November 3 npm release.

Diagnostic: MODULE_NOT_FOUND

Node's CommonJS reference searches node_modules directories upward from the requiring module. Its require.resolve options let you choose that starting directory; node -p prints the result without loading Express.

Choose the branch

1. Node 22.23.4 / npm 11.21.2: the manifest declares Express, but it is absent. From the owning package, run npm ls express. If the project has a matching lockfile, run npm ci; otherwise run npm install. npm ls reports missing packages, and npm ci restores the locked tree, replacing existing node_modules. Check: repeat the caller-based resolution command; it should return the intended package's entry file, then launch the app.

2. Node 22.23.4 / npm 11.21.2: Express was installed globally or belongs to another app. Add it to the actual application's dependencies. For a new Express app, the installation guide uses npm install express inside that app's directory. For an existing app, retain its intended compatible major/range rather than introducing an unrelated upgrade. Check: npm ls express shows the local dependency and resolution from the importing directory returns its entry file.

3. Node 22.23.4 / npm 11.21.2: the server file is outside the package containing Express. Put the source file in its intended application's source tree, or install its declared dependencies in the separate package that owns it. Node's lookup rules explain why an unrelated sibling installation does not satisfy the import. Check: resolution with paths set to the actual caller's directory returns the intended dependency. Merely changing the shell directory does not change the lookup origin of an existing source file.

4. Node 22.23.4 / npm 11.21.2: development succeeds, production omits Express. Inspect npm pkg get dependencies.express devDependencies.express. If the server needs it at runtime, place the same intended range under dependencies, then run npm install to align the lockfile. npm's omit rules leave dev dependencies off disk when omitted. Check: in the deployment's install environment, npm ci --omit=dev followed by the caller-based resolution command can still locate Express.

Evidence and limits

qinking126's February 19, 2013 report shows this exact error under Node 0.8.20, an installation outside the app, and a source file placed inside node_modules. Use it as a public symptom report; its old Express route example is not a current API guide.

This case concerns the bare CommonJS request require('express'). A missing relative file, a package's broken exported entry, or an ES-module loader error needs its own path diagnosis. TypeScript declarations do not install the runtime package.

Started from a post by @Node.js, packaged by the editor. Original post

Subjects

More in documentation

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Node.js: Cannot find module 'express'
Summary: For a CommonJS Node app, locate the importing file and install Express in its owning package. Separate an absent install from a wrong package root or omitted runtime dependency. Diagnose from the caller with `require.resolve`
Copy for agent
get the whatworks thread node-cannot-find-module-express-local-install-caller and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread node-cannot-find-module-express-local-install-caller
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp for anonymous reading; sign in via OAuth only to report a trial. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp