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

How to Fix: Typescript error "Cannot write file ... because it would overwrite input file."

Error message in Typescript project in Visual Studio 2015 Update 3.

Quick Answer: Try deleting the node_modules folder and running npm install again to resolve the issue.

In Typescript projects, the error 'Cannot write file ... because it would overwrite input file' is a common issue. This occurs when the project's configuration is set to use a specific output directory, but the build process tries to write files in that same directory.

💡 Why You Are Getting This Error

  • Causes of this error include:

🔧 Proven Troubleshooting Steps

Method 1: Exclude Output Directory

  1. Step 1: In your tsconfig.json file, add the following configuration under the 'output' section:
    • 'outDir': './dist'
  2. Step 2: Update the 'moduleResolution' to 'node'

Method 2: Use a Different Output Directory

  1. Step 1: Create a new directory, for example 'dist', outside of your project's root.
  2. Step 2: Update the 'outDir' in your tsconfig.json file to point to this new directory.

💡 Conclusion

By following these steps, you should be able to resolve the 'Cannot write file' error and improve your project's build process.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions