Skip to content
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

.json inputs not allowed outside of rootDir #38015

Closed
duarten opened this issue Apr 17, 2020 · 7 comments
Closed

.json inputs not allowed outside of rootDir #38015

duarten opened this issue Apr 17, 2020 · 7 comments
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@duarten
Copy link

duarten commented Apr 17, 2020

TypeScript Version: Version 3.8.3

Search Terms: json rootDir

Code

Folder structure:

src/test.ts
src/tsconfig.json
data/dummy.json

tsconfig:

{
    "compilerOptions": {
        "esModuleInterop": true,
        "resolveJsonModule": true,
        "rootDirs": [
            ".",
            "../data"
        ]
    }
}

test.ts:

import dummy from "./dummy.json"

console.log(dummy)

Expected behavior:

JSON printed to stdout.

Actual behavior:

The error: src/test.ts:1:19 - error TS6059: File 'repro/data/dummy.json' is not under 'rootDir' 'repro/src'. 'rootDir' is expected to contain all source files.

Playground Link:

Related Issues:

@RyanCavanaugh RyanCavanaugh added Working as Intended The behavior described is the intended behavior; this is not a bug Needs Investigation This issue needs a team member to investigate its status. and removed Working as Intended The behavior described is the intended behavior; this is not a bug labels Apr 17, 2020
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 4.0 milestone Apr 17, 2020
@sheetalkamat
Copy link
Member

sheetalkamat commented Apr 21, 2020

This does not repro and does not repro error with latest from master

c:\temp\test>dir /S
 Volume in drive C is OSDisk
 Volume Serial Number is F41A-DBC9

 Directory of c:\temp\test

04/21/2020  11:14 AM    <DIR>          .
04/21/2020  11:14 AM    <DIR>          ..
04/21/2020  11:12 AM    <DIR>          data
04/21/2020  11:14 AM    <DIR>          src
               0 File(s)              0 bytes

 Directory of c:\temp\test\data

04/21/2020  11:12 AM    <DIR>          .
04/21/2020  11:12 AM    <DIR>          ..
04/21/2020  11:13 AM                11 dummy.json
               1 File(s)             11 bytes

 Directory of c:\temp\test\src

04/21/2020  11:14 AM    <DIR>          .
04/21/2020  11:14 AM    <DIR>          ..
04/21/2020  11:14 AM               286 test.js
04/21/2020  11:11 AM                54 test.ts
04/21/2020  11:11 AM               182 tsconfig.json
               3 File(s)            522 bytes

     Total Files Listed:
               4 File(s)            533 bytes
               8 Dir(s)  736,388,980,736 bytes free

c:\temp\test>node c:\TypeScript\built\local\tsc.js --listFiles --p src
c:/TypeScript/built/local/lib.d.ts
c:/TypeScript/built/local/lib.es5.d.ts
c:/TypeScript/built/local/lib.dom.d.ts
c:/TypeScript/built/local/lib.webworker.importscripts.d.ts
c:/TypeScript/built/local/lib.scripthost.d.ts
c:/temp/test/data/dummy.json
c:/temp/test/src/test.ts

@sheetalkamat sheetalkamat removed their assignment Apr 21, 2020
@sheetalkamat sheetalkamat added Needs More Info The issue still hasn't been fully clarified and removed Needs Investigation This issue needs a team member to investigate its status. labels Apr 21, 2020
@sheetalkamat sheetalkamat removed this from the TypeScript 4.0 milestone Apr 21, 2020
@duarten
Copy link
Author

duarten commented Apr 21, 2020

Specifying rootDir is an integral part of this issue. The command to run is tsc --project src/tsconfig.json --outDir lib/ --rootDir src. That will reproduce it:

tsc --project src/tsconfig.json --outDir lib/ --rootDir src
src/test.ts:1:19 - error TS6059: File '/Users/duarten/code/ts-issue/data/dummy.json' is not under 'rootDir' '/Users/duarten/code/ts-issue/src'. 'rootDir' is expected to contain all source files.

1 import dummy from "./dummy.json"
                    ~~~~~~~~~~~~~~


Found 1 error.

@sheetalkamat
Copy link
Member

The issue is not rootDir but outDir when you specify outDir you are saying all the files in the program need to go into the outDir folder and the common source directory for all the files is rootDir. Clearly dummy.json is not in it hence the error. This is intended behavior

c:\temp\test>node c:\TypeScript\built\local\tsc.js  -p src  --rootDir src

c:\temp\test>node c:\TypeScript\built\local\tsc.js  -p src  --rootDir src --outDir lib
src/test.ts:1:19 - error TS6059: File 'c:/temp/test/data/dummy.json' is not under 'rootDir' 'c:/temp/test/src'. 'rootDir' is expected to contain all source files.

1 import dummy from "./dummy.json"
                    ~~~~~~~~~~~~~~

@sheetalkamat sheetalkamat added Working as Intended The behavior described is the intended behavior; this is not a bug and removed Needs More Info The issue still hasn't been fully clarified labels Apr 21, 2020
@duarten
Copy link
Author

duarten commented Apr 21, 2020

Why does TypeScript need to put the JSON files in the outDir? Couldn't it treat them like d.ts files, which can be outside of the rootDir?

@sheetalkamat
Copy link
Member

.json files are like .js files and will be emitted .. only special casing is they are emitted if the emit would overwrite them

@duarten
Copy link
Author

duarten commented Apr 21, 2020

I see, thanks! Although I find it weird that json files are treated differently than, say, css files.

@typescript-bot
Copy link
Collaborator

This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

4 participants