Skip to content

Compiler outputs files to the wrong directory structure #5809

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
enlight opened this issue Nov 27, 2015 · 6 comments
Closed

Compiler outputs files to the wrong directory structure #5809

enlight opened this issue Nov 27, 2015 · 6 comments

Comments

@enlight
Copy link

enlight commented Nov 27, 2015

I've noticed a couple of issues with the way the compiler resolves the output directory structure. I've created a minimal project that can be used to reproduce these issues, it's setup as an NPM package, so after cloning/extracting run npm install to install the latest nightly build of TypeScript (support for filenames in the --project compiler option was added very recently).

Issue 1

From the package root run

node ./node_modules/typescript/bin/tsc --project src/good-tsconfig.json

Note that the output directory structure is (as expected):

lib/
  first/
    file1.js
  second/
    file2.js

Now run

node ./node_modules/typescript/bin/tsc --project src/bad-tsconfig.json

Note that the output directory structure is missing the subdir second:

lib2/
  file2.js

While the expected output directory structure is:

lib2/
  second/
    file2.js

Issue 2

I'm not sure if this is a bug or just user error, but it can be reproduced starting with TypeScript 1.6.2 (and possibly earlier, that's just the oldest version I've tried). Run

node ./node_modules/typescript/bin/tsc --project src/second

Note that the output directory structure is:

lib3/
  second/
    first/
      file1.js
    second/
      file2.js

While the expected output directory structure is:

lib3/
  first/
    file1.js
  second/
    file2.js
@falsandtru
Copy link
Contributor

--rootDir option will solve your issue. See: https://github.com/Microsoft/TypeScript/wiki/Compiler-Options

@enlight
Copy link
Author

enlight commented Nov 27, 2015

Thanks for the tip @falsandtru. Setting rootDir to . in bad-tsconfig.json does indeed solve the first issue, though it seems to me like that ought to be the default value of rootDir anyway.

Unfortunately I can't seem to fix the second issue by setting rootDir, I've tried modifying src/second/tsconfig.json like so:

{
    "compilerOptions": {
        "module": "commonjs",
        "target": "es6",
        "noImplicitAny": true,
        "sourceMap": false,
        "declaration": false,
        "noLib": false,
        "outDir": "../../lib3",
        "rootDir": ".."
    },
    "files": [
        "first/file1.ts",
        "second/file2.ts"
    ]
}

but the compiler then fails to find the source files:

error TS6053: File 'src/second/first/file1.ts' not found.
error TS6053: File 'src/second/second/file2.ts' not found.

@falsandtru
Copy link
Contributor

Correct code:

{
    "compilerOptions": {
        "module": "commonjs",
        "target": "es6",
        "noImplicitAny": true,
        "sourceMap": false,
        "declaration": false,
        "noLib": false,
        "outDir": "../../lib3",
        "rootDir": ".."
    },
    "files": [
        "../first/file1.ts",
        "../second/file2.ts"
    ]
}

@enlight
Copy link
Author

enlight commented Nov 27, 2015

That does indeed work, thanks @falsandtru.

@falsandtru
Copy link
Contributor

Not at all. Let's complete a issue with closing of it.

@enlight
Copy link
Author

enlight commented Nov 27, 2015

For future reference, the explanation of the rootDir option in #2772 is vastly better than the two short sentences written about it in https://github.com/Microsoft/TypeScript/wiki/Compiler-Options

@enlight enlight closed this as completed Nov 27, 2015
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants