【问题标题】:index.ts is missing from the TypeScript compilationTypeScript 编译中缺少 index.ts
【发布时间】:2019-01-05 10:41:12
【问题描述】:

运行“ng serve”时出现以下错误。

node_modules/angular2-indexeddb/index.ts 从 TypeScript 编译。请确保它在您的 tsconfig 中 “文件”或“包含”属性。丢失的文件似乎是一部分 第三方库。已发布库中的 TS 文件通常是 包装不良的图书馆的标志。请在库中打开一个问题 存储库以提醒其作者并要求他们打包库 使用 Angular 包格式 (https://docs.google.com/document/d/1CZC2rcpxffTDfRDs6p1cfbmKNLA6x5O-NtkJglDaBVs/preview)。

我想问题是 tsconfig 没有将 angular2-indexeddb 纳入编译。 https://github.com/gilf/angular2-indexeddb

我认为应该通过在 tslint.json 中编辑以下配置来临时解决问题,但我需要一个解决方案来解决它。

  "include": [
    "**/*.spec.ts",
    "**/*.d.ts"
  ] 

是不是因为 angular2-indexeddb 没有提供好的打包库?事实上,我不认为一个流行的出版图书馆应该有这个问题。或者我错过了一些配置或编译的东西?可以使用包编译工具/库编译成d.ts或者spec.ts吗?

更新:

其实我在目录下看到*.d.ts文件:

ls node_modules/angular2-indexeddb/
LICENSE                                 angular2-indexeddb.metadata.json        index.js
README.md                               angular2-indexeddb.min.js               index.js.map
angular2-indexeddb.d.ts                 angular2-indexeddb.min.js.map           index.ts
angular2-indexeddb.js                   angular2-indexeddb.ts                   package.json
angular2-indexeddb.js.map               index.d.ts

tsconfig.json 中的内容:

{
  "compileOnSave": false,
  "compilerOptions": {
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es5",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2017",
      "dom"
    ]
  }
}

【问题讨论】:

    标签: angular typescript indexeddb tslint tsconfig


    【解决方案1】:
    {
        "include": [
              "../src/**/*",
              "../node_modules/angular2-indexeddb/index.ts"
        ]
    }
    

    编辑:我建议您将 lib 更改为 ngx-indexed-db,因此您不需要这样做。

    【讨论】:

    • 是在“compilerOptions”下的tsconfig.json文件中吗?我收到以下错误:tsconfig.json(18,5): error TS5023: Unknown compiler option 'exclude'.
    • 它不在compilerOptions里面,它在同一级别
    • 我在添加排除 node_modules 后仍然看到同样的问题,我想这是因为我没有添加文件和包含。标准的 tsconfig.json 是什么样的?我从来没有改变过 tsconfig.json,其他库都可以。
    • 查看现在已编辑,尝试包含该内容。如果您使用的是新的 CLI 版本,则必须在 tsconfig.app.json 中对其进行编辑
    • 添加后出现新错误:/src/main.ts is missing from the TypeScript 编译。请通过 'files' 或 'include' 属性确保它在您的 tsconfig 中。
    猜你喜欢
    • 2018-07-11
    • 1970-01-01
    • 2018-10-01
    • 2020-11-26
    • 2018-08-12
    • 1970-01-01
    • 1970-01-01
    • 2021-02-12
    • 1970-01-01
    相关资源
    最近更新 更多