Ako odstrániť chybu "Cannot write file ... because it would overwrite input file."
Pri práci s TypeScriptom a konfiguráciou vždy keď som zadal exclude som dostal veľké množstvo errorov. Dlho som nevedel nájsť riešenie až nakoniec som našiel issue 14538, kde bolo aj riešenie. Príklad: Pôvodný (chybný) tsconfig.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
{
"exclude": [
"node_modules"
],
"compilerOptions": {
"module": "commonjs",
"charset": "utf-8",
"baseUrl": "./src/typescript",
"outDir": "./dist/js",
"target": "es6",
"sourceMap": true,
"watch": true,
"moduleResolution": "node",
"noEmitOnError": true,
"checkJs": true,
"allowJs": true,
"experimentalDecorators": true
}
}
Pre odstránenie tohto problému musím pridať do exclude aj outDir. Finálny tsconfig.json vyzerá nasledovne.Príklad: Opravený tsconfig.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
{
"exclude": [
"node_modules",
"dist"
],
"compilerOptions": {
"module": "commonjs",
"charset": "utf-8",
"baseUrl": "./src/typescript",
"outDir": "./dist/js",
"target": "es6",
"sourceMap": true,
"watch": true,
"moduleResolution": "node",
"noEmitOnError": true,
"checkJs": true,
"allowJs": true,
"experimentalDecorators": true
}
}
Záver
Verím, že vám tento článok pomohol a zbavili ste sa všetkých errorov, ktoré vám pri spustení kompilátora vznikali. 7.8.2018 (aktualizované 8.8.2018), Matej LednárKategória: ProgramovanieProgramovanie,TypeScript,tsconfig.json,exclude,node_modules,overwrite,input,file,compilerOptions,configurationŽiadna časť tohto článku nesmie byť reprodukovaná bez uvedenia autora a URL na túto stránku.Viac informácií nájdete v sekcii O projekte.