Software⏱️ 2 min read📅 2026-05-31

How to Fix: TypeScript getting error TS2304: cannot find name ' require'

Learn how to fix: TypeScript getting error TS2304: cannot find name ' require'.

Quick Answer: Try checking your system settings or restarting.

The error TS2304: Cannot find name 'require' is typically caused by TypeScript not being able to resolve the 'require' function, which is a part of Node.js. This can happen when you're trying to use the 'require' function in your TypeScript code without properly configuring your project.

🔍 Why This Happens

  • [Cause]

✅ Best Solutions to Fix It

Method 1: Using the Node.js Include Path

  1. Step 1: Add the following line to your tsconfig.json file under the 'compilerOptions' section:
paths: { 'node': 'node_modules' },

Step 2:: Run the command tsc --build to rebuild your project with the updated tsconfig.json file.

Method 2: Using the 'node' module in your TypeScript File

  1. Step 1: Import the 'require' function from the 'node' module using the following syntax:
import { require } from 'node';

Step 2:: Use the 'require' function as needed in your code.

💡 Conclusion

By following these steps, you should be able to resolve the TS2304: Cannot find name 'require' error and get your TypeScript Node.js application up and running.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions