Visual Studio - >共享TypeScript库 - > TS6059文件''不在'rootDir'''下。 'rootDir'应包含所有源文件 [英] Visual Studio -> Shared TypeScript Library -> TS6059 File '' is not under 'rootDir' ''. 'rootDir' is expected to contain all source files
问题描述
我们正在使用 Visual Studio 2017
并且有两个独立的Web项目应该共享一些 React
写的组件在 TypeScript
中。还可以共享 JavaScript
文件和 CSS
文件。为此,我们在Visual Studio中创建了一个共享项目
。
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'
}
对于测试,我可以像这样引用它,Visual Studio将找到该文件:
For testing I can reference it like this and Visual Studio will locate the file:
import { Types} from '../../../2/Constants/Types'
然而,当我尝试运行 webpack
时,我收到以下错误:
However when I then try to run webpack
I get the following error:
TS6059:文件'/2/Constants/Types.ts'不在
'rootDir''/ 1'之下。 'rootDir'应包含所有源
文件。
TS6059: File '/2/Constants/Types.ts' is not under 'rootDir' '/1'. 'rootDir' is expected to contain all source files.
推荐答案
找到我的 tsconfig.json
中的问题。我有以下价值:
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
这篇关于Visual Studio - >共享TypeScript库 - > TS6059文件''不在'rootDir'''下。 'rootDir'应包含所有源文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!