Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio -> Shared TypeScript Library -> TS6059 File '' is not under 'rootDir' ''. 'rootDir' is expected to contain all source files

We are using Visual Studio 2017 and have two separate web projects that are supposed to share some React components written in TypeScript. There can also be shared JavaScript files and CSS files. For this we have created a Shared Project in Visual Studio.

What is the difference between a Shared Project and a Class Library in Visual Studio 2015?

Right now the project only has a single file with this information.

export const Types = {
    Type1: '1',
    Type2: '2',
    Type3: '3'
}

For testing I can reference it like this and Visual Studio will locate the file:

import { Types} from '../../../2/Constants/Types'

However when I then try to run webpack I get the following error:

TS6059: File '/2/Constants/Types.ts' is not under 'rootDir' '/1'. 'rootDir' is expected to contain all source files.

like image 271
Ogglas Avatar asked Jan 10 '18 14:01

Ogglas


2 Answers

Found the problem in my tsconfig.json. I had the following value:

"rootDir": ".",

If I changed it to this it started working:

"rootDir": "../",

However the default value was this according to the handbook:

common root directory is computed from the list of input files

After reading this I decided to remove the value altogether and let the compiler set the default value instead.

https://www.typescriptlang.org/docs/handbook/compiler-options.html

like image 82
Ogglas Avatar answered Oct 01 '22 20:10

Ogglas


I used the rootDirs compiler option for this purpose and it seems to work swell!

"rootDirs": [
  "../some/folder/outside",
  "src",
]
like image 26
jedmao Avatar answered Oct 01 '22 19:10

jedmao