【问题标题】:Visual Studio -> Shared TypeScript Library -> TS6059 File '' is not under 'rootDir' ''. 'rootDir' is expected to contain all source filesVisual Studio -> 共享 TypeScript 库 -> TS6059 文件 '' 不在 'rootDir' '' 下。 'rootDir' 应包含所有源文件
【发布时间】:2018-06-19 18:12:24
【问题描述】:

我们正在使用Visual Studio 2017 并且有两个独立的网络项目,它们应该共享一些用TypeScript 编写的React 组件。还可以共享JavaScript 文件和CSS 文件。为此,我们在 Visual Studio 中创建了一个Shared Project

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

目前该项目只有一个包含此信息的文件。

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

为了测试,我可以这样引用它,Visual Studio 将找到该文件:

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

但是,当我尝试运行 webpack 时,出现以下错误:

TS6059:文件“/2/Constants/Types.ts”不在 'rootDir' '/1'。 'rootDir' 应包含所有源 文件。

【问题讨论】:

    标签: javascript visual-studio typescript webpack typescript2.0


    【解决方案1】:

    我为此使用了 rootDirs 编译器选项,它似乎工作得很好!

    "rootDirs": [
      "../some/folder/outside",
      "src",
    ]
    

    【讨论】:

      【解决方案2】:

      在我的tsconfig.json 中发现了问题。我有以下值:

      "rootDir": ".",
      

      如果我把它改成这个,它就开始工作了:

      "rootDir": "../",
      

      但是根据手册,默认值是这样的:

      根据输入文件列表计算公共根目录

      读完这篇文章后,我决定完全删除这个值,让编译器设置默认值。

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

      【讨论】:

        猜你喜欢
        • 2019-12-16
        • 2021-09-16
        • 1970-01-01
        • 2019-01-21
        • 2018-12-06
        • 1970-01-01
        • 2020-07-10
        • 2019-04-12
        • 2022-10-02
        相关资源
        最近更新 更多