Warning: session_start(): open(/tmp/sess_473b4cd338500f0cfee34810d1591f1a, O_RDWR) failed: Disk quota exceeded (122) in /home/wvyrfnwn/learnshareit.com/wp-content/plugins/learnpress/inc/class-lp-page-controller.php on line 1007

Warning: session_start(): Failed to read session data: files (path: /tmp) in /home/wvyrfnwn/learnshareit.com/wp-content/plugins/learnpress/inc/class-lp-page-controller.php on line 1007

Warning: ftp_nlist() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 420

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_nlist() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 420

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 719

Warning: ftp_nlist() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 420

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_nlist() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 420

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 719

Warning: ftp_mkdir() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 562

Warning: ftp_nlist() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 420

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230
Cannot write file # because it would overwrite input file error in TypeScript - How to fix it? - LearnShareIT

Cannot write file # because it would overwrite input file error in TypeScript – How to fix it?

"Cannot write file because it would overwrite input file" error in TS

If you are having trouble with the “Cannot write file # because it would overwrite input file” error in TypeScript, then this article is for you. Let’s figure out the solution to this problem as well as the reason why the error occurs in your project.

Why do we get this error message?

The error “Cannot write file # because it would overwrite input file” error in TypeScript happens because, in the tsconfig.json file, we did not indicate the ‘outDir‘ directory inside the ‘exclude‘ array.

Sometimes the error can also happen because you import a file from the specified ‘outDir’ directory or use Monorepos in your project.

Solution for “Cannot write file # because it would overwrite input file” error in TypeScript

To get around this error, open the file ‘tsconfig.json’ and check if your ‘outDir’ is in the array ‘exclude‘ or not. You must ensure the project’s build directory is excluded. To illustrate, your ‘tsconfig.json’ should be like this:

{
  "compilerOptions": {
    "outDir": "build",
  },

  "exclude": ["node_modules", "build/**/*"]
  //…other options
}

If the array ‘exclude’ does not contain the value you declared for the ‘outDir’ option, modify it like in the example above. The build directory is specified for TypeScript to output emitted files in this example.

After reconfiguring the tsconfig.json file, restart the IDE as well as the development server so that the system can correctly update the latest changes.

In addition, you also need to make sure you don’t import any function or anything else from your ‘outDir’ directory. For example:

import { firstFunc } from "../../../build/myFolder/FirstFunction";
//or
import { secondFunc } from "../../../dist/myFolder/SecondFunction";

In the above example, we describe the case where you import a function from the directory ‘build’/ ‘dist’, which are the two most commonly given names for the ‘outDir’ option. It may be different as you work on your project, leaning on how you name it.


The last thing to keep in mind to avoid getting errors “Cannot write file # because it would overwrite input file” is to ensure that there are no circular dependencies in your project. Here is an example:

In Home.ts:

import { Contact } from "./About";

export interface WelcomeMessage {
  message(s: string): string;
}

In About.ts:

import { WelcomeMessage } from "./Home";

export interface Contact {
  email(s: string): string;
}

It can be seen that two files, ‘Home.ts’ and ‘About.ts’, are interdependent. Because of ‘Home.ts’ imports from ‘About.ts’ and vice versa. This will cause trouble for your project, especially when you use Monorepos.

Summary

To sum up, the necessary information about “Cannot write file # because it would overwrite input fileerror in TypeScript has been conveyed by us through this article. Thanks for being so interested, and good luck with your upcoming projects.

Maybe you are interested:

Leave a Reply

Your email address will not be published. Required fields are marked *