14

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.

Ogglas
  • 62,132
  • 37
  • 328
  • 418

2 Answers2

21

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

"rootDirs": [
  "../some/folder/outside",
  "src",
]
jedmao
  • 10,224
  • 11
  • 59
  • 65
19

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

Ogglas
  • 62,132
  • 37
  • 328
  • 418