Ts-node: Cannot write file because it would be overwritten by multiple input files

Created on 25 Sep 2017  Â·  7Comments  Â·  Source: TypeStrong/ts-node

I keep having a problem where ts-node won't work with multi-module projects.
The local modules are linked using npm link.
They often reference each other so a dependency(npm link) chain may look like
A -> B -> C
(project's submodule depends on a "commons" module)
+
(project depends on "commons" module for type definitions etc.)
A -> C
But that's probably not the main cause on this problem?

This breaks developer experience very badly because I am unable to run unit tests with ts-node while developing, so I have to go every time $ npm run build $ mocha lib/tests/test_something.js etc...

TSError: ⨯ Unable to compile TypeScript
Cannot write file 'C:/Users/x/IdeaProjects/PROJECT/MODULE1/$$ts-node$$/SYMLINKED_SUBMODULE/lib/src/util/index.js' because it would be overwritten by multiple input files. (5056)

Most helpful comment

it seems like the problem is caused by using allowJs=true and removing it from tsconfig helps 🤔

All 7 comments

I guess adding this option from tsconfig.json to ts-node would fix it ?

    "exclude":["node_modules"],

it seems like the problem is caused by using allowJs=true and removing it from tsconfig helps 🤔

I too am running into this.

My only guess is that you have both .js and .ts right next to each other. TypeScript would be resolving the .ts file during compilation, but node.js would be resolving the .js file during resolution. When allowJs is enabled it'd be trying to compile .js when node.js loads the file, resulting in the overlap.

For anyone coming here in future: try adding -O '{"allowJs":false,"checkJs":false}' as an argument to your ts-node call.

Perhaps you need to exclude your build output files as well? As it's compiling down to JavaScript you want to make sure it's not grabbing that JavaScript build output and trying to build it again.

"outDir": "build",
"exclude": [
"node_modules",
"build"
],

Closing because Blake's assessment looks correct and I don't think this requires any further action from us.

Was this page helpful?
0 / 5 - 0 ratings