Skip to content

tsconfig outDir does not keep directory structure #5134

Closed
@editedredx

Description

@editedredx

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.

Activity

added this to the TypeScript 1.7 milestone on Oct 6, 2015
self-assigned this
on Oct 6, 2015
added
FixedA PR has been merged for this issue
on Oct 6, 2015
mhegazy

mhegazy commented on Oct 6, 2015

@mhegazy
Contributor

should be fixed by @denvned in #4724. should be in typescript@next tonight after 12:00 am PST

denvned

denvned commented on Oct 7, 2015

@denvned
Contributor

@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

Yugloocamai commented on Jan 13, 2017

@Yugloocamai

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

craxal commented on Feb 6, 2017

@craxal

Still happening to me in Typescript 2.1.5. This is very, very wrong. Is anyone else still encountering this issue?

  • my-project
    • dist
      • file.js
    • src
      • dir
        • file.ts
    • tsconfig.json

outDir is set to "dist". The problem magically goes away, however, if I have a Typescript file located directly under "src":

  • my-project
    • dist
      • dir
        • file.js
      • empty.js
    • src
      • dir
        • file.ts
      • empty.ts
    • tsconfig.json
mhegazy

mhegazy commented on Feb 6, 2017

@mhegazy
Contributor
craxal

craxal commented on Feb 6, 2017

@craxal

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

mhegazy commented on Feb 6, 2017

@mhegazy
Contributor

this logic was in place before tsconfig.json support was added.

craxal

craxal commented on Feb 7, 2017

@craxal

What about the tsc command? Why was this logic chosen?

CorpulentBrony

CorpulentBrony commented on Feb 23, 2017

@CorpulentBrony

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.

  • With neither outDir nor rootDir set, the JS file is created as ts/server/code.js
  • With outDir set to /var/www/project, the JS file is created as ./code.js
  • With outDir set to /var/www/project and rootDir set to ./, the JS file is created as ts/server/code.js
  • With rootDir set to ./, the JS file is created as ts/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

mhegazy commented on Feb 23, 2017

@mhegazy
Contributor

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

CorpulentBrony

CorpulentBrony commented on Feb 23, 2017

@CorpulentBrony
{
	"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"
	]
}
mhegazy

mhegazy commented on Feb 23, 2017

@mhegazy
Contributor

The output will be generated in /var/www/project/ts/server/code.js where do you see it generated?

CorpulentBrony

CorpulentBrony commented on Feb 23, 2017

@CorpulentBrony

That is where it is being generated. I want to see it generated in /var/www/project/server/code.js

mhegazy

mhegazy commented on Feb 23, 2017

@mhegazy
Contributor

set "rootDir": "./ts" instead

CorpulentBrony

CorpulentBrony commented on Feb 23, 2017

@CorpulentBrony

Thank you, that worked!

locked and limited conversation to collaborators on Jun 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @editedredx@craxal@denvned@mhegazy@CorpulentBrony

      Issue actions

        tsconfig outDir does not keep directory structure · Issue #5134 · microsoft/TypeScript