I'm on version 1.6.2
Using directory structure
- temp
- some
- dir
- foo.ts
- tsconfig.json
and tsconfig.json only contains:
{
"compilerOptions": {
"outDir": "build/"
}
}
than when running tsc inside temp I'm expecting foo.js in path /temp/build/some/dir/foo.js, it's actually in /temp/build/foo.js.
It's the same result as running tsc --outDir build with an empty tsconfig, while it should be the same as tsc --rootDir . --outDir build since "The presence of a tsconfig.json file in a directory indicates that the directory is the root of a TypeScript project".
Adding a rootDir key to the compilerOptions in the json does not seem to help either.
should be fixed by @denvned in #4724. should be in typescript@next tonight after 12:00 am PST
@editedredx but note, that even after the fix #4724, you should use the rootDir option to achieve what you want, because otherwise it defaults to the common path prefix of all the sources.
This default to the common path prefix of all the sources behavior is the worst. Removing levels of directory structure should always be something you set on purpose, not a default behavior.
Still happening to me in Typescript 2.1.5. This is very, very wrong. Is anyone else still encountering this issue?
outDir is set to "dist". The problem magically goes away, however, if I have a Typescript file located directly under "src":
@craxal use --rootDir ./. see https://github.com/Microsoft/TypeScript/wiki/FAQ#why-does---outdir-moves-output-after-adding-a-new-file for more details.
OK, that works. Sorry, didn't see the comment.
Why does the compiler have to "compute" this? Why doesn't is just use the same directory as the tsconfig.json (".") or the current working directory of the tsc command?
this logic was in place before tsconfig.json support was added.
What about the tsc command? Why was this logic chosen?
I can't figure out how to get this to work, I'm having the exact same problem. Off of the project root, I have a ts/server/code.ts file and I want it to be transpiled and the JS file created as server/code.js.
So what is needed to get it to work properly? Do I just need a blank TS file in ts/server?
I'm running TS 2.3.0-dev.20170223 right now.
So what is needed to get it to work properly? Do I just need a blank TS file in ts/server?
I do not think so. Can you share your tsconfig.json
{
"compileOnSave": true,
"compilerOptions": {
"allowJs": true,
"allowUnusedLabels": true,
"charset": "utf-8",
"experimentalDecorators": true,
"module": "commonjs",
"moduleResolution": "node",
"noFallthroughCasesInSwitch": false,
"noImplicitReturns": true,
"outDir": "/var/www/project",
"pretty": false,
"removeComments": true,
"rootDir": "./",
"stripInternal": true,
"target": "es6"
},
"exclude": [
"typings/Promise.d.ts"
],
"files": [
"typings/index.d.ts",
"ts/server/code.ts"
]
}
The output will be generated in /var/www/project/ts/server/code.js where do you see it generated?
That is where it is being generated. I want to see it generated in /var/www/project/server/code.js
set "rootDir": "./ts" instead
Thank you, that worked!
Most helpful comment
This default to the common path prefix of all the sources behavior is the worst. Removing levels of directory structure should always be something you set on purpose, not a default behavior.