Closed
Description
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.
Metadata
Metadata
Assignees
Type
Projects
Relationships
Development
No branches or pull requests
Activity
mhegazy commentedon Oct 6, 2015
should be fixed by @denvned in #4724. should be in
typescript@next
tonight after 12:00 am PSTdenvned commentedon Oct 7, 2015
@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.
Yugloocamai commentedon Jan 13, 2017
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.
craxal commentedon Feb 6, 2017
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":mhegazy commentedon Feb 6, 2017
@craxal use
--rootDir ./
. see https://github.com/Microsoft/TypeScript/wiki/FAQ#why-does---outdir-moves-output-after-adding-a-new-file for more details.craxal commentedon Feb 6, 2017
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?mhegazy commentedon Feb 6, 2017
this logic was in place before
tsconfig.json
support was added.craxal commentedon Feb 7, 2017
What about the
tsc
command? Why was this logic chosen?CorpulentBrony commentedon Feb 23, 2017
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.
mhegazy commentedon Feb 23, 2017
I do not think so. Can you share your tsconfig.json
CorpulentBrony commentedon Feb 23, 2017
mhegazy commentedon Feb 23, 2017
The output will be generated in
/var/www/project/ts/server/code.js
where do you see it generated?CorpulentBrony commentedon Feb 23, 2017
That is where it is being generated. I want to see it generated in /var/www/project/server/code.js
mhegazy commentedon Feb 23, 2017
set
"rootDir": "./ts"
insteadCorpulentBrony commentedon Feb 23, 2017
Thank you, that worked!
Add rootDir to compilerOptions
Add rootDir to TypeScript compiler options
Add unit tests, update versions and Travis build