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.
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
I used the rootDirs compiler option for this purpose and it seems to work swell!
"rootDirs": [
"../some/folder/outside",
"src",
]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With