2

我有一个 Nativescript 代码共享项目。typescript 无法解析具有 tns.ts 扩展名的文件中的模块。我收到以下消息。我认为这是因为 tsconfig.json 中排除了所有 tns.ts、android.ts 和 ios.ts 文件。

找不到模块

这来自https://github.com/NativeScript/web-mobile-project项目。我添加了第 5 行来显示错误。第 13 行也有一个错误。它说应该启用实验装饰器。它在两个配置文件中都启用了,但我仍然收到此错误,因为 tsconfig.tns.json 和 tsconfig.json 文件被忽略。

仅当文件扩展名为 tns.ts 时才会发生这种情况。找到没有 tns.ts 扩展名的文件中的所有模块,并且Atom 编辑器不显示错误。

我怎么解决这个问题?

这是我的 tsconfig.json 文件:

{
    "compileOnSave": false,
    "compilerOptions": {
        "outDir": "./dist/out-tsc",
        "declaration": false,
        "moduleResolution": "node",
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "target": "es5",
        "typeRoots": [
            "node_modules/@types"
        ],
        "lib": [
            "es2017",
            "dom",
            "es6",
            "es2015.iterable"
        ],
        "baseUrl": "./",
        "paths": {
            "~/*": [
                "src/*"
            ],
            "*": [
                "./node_modules/tns-core-modules/*",
                "./node_modules/*"
            ],
            "@shared/*": [
                "src/app/shared/*"
            ],
            "@models/*": [
                "src/app/shared/models/*"
            ],
            "@core/*": [
                "src/app/core/*"
            ],
            "@components/*": [
                "src/app/components/*"
            ]
        }
    },
    "exclude": [
        "**/*.tns.ts",
        "**/*.android.ts",
        "**/*.ios.ts",
        "**/*.spec.ts"
    ]
}

这是 tsconfig.tns.json:

{
  "extends": "./tsconfig.json",
  "compilerOptions": {
    "module": "es2015",
    "moduleResolution": "node",
    "baseUrl": "./",
    "experimentalDecorators": true,
    "paths": {
      "~/*": [
          "src/*"
      ],
      "*": [
          "./node_modules/tns-core-modules/*",
          "./node_modules/*"
      ],
      "@shared/*": [
          "src/app/shared/*"
      ],
      "@models/*": [
          "src/app/shared/models/*"
      ],
      "@core/*": [
          "src/app/core/*"
      ],
      "@components/*": [
          "src/app/components/*"
      ]
    }
  }
}
4

0 回答 0