更新角度4.4到6后,缺少TypeScript编译错误

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了更新角度4.4到6后,缺少TypeScript编译错误相关的知识,希望对你有一定的参考价值。

我将4.4角应用更新为角6。

我有几个错误,但我修复了它们,现在当我运行npm run start时,在编译结束时(大约92%)我得到以下错误:

ERROR in ./node_modules/ngx-lorem-ipsum/lib/ngx-lorem-ipsum.component.ts
Module build failed: Error: /application/node_modules/ngx-lorem-ipsum/lib/ngx-lorem-ipsum.component.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property.
The missing file seems to be part of a third party library. TS files in published libraries are often a sign of a badly packaged library. Please open an issue in the library repository to alert its author and ask them to package the library using the Angular Package Format (https://docs.google.com/document/d/1CZC2rcpxffTDfRDs6p1cfbmKNLA6x5O-NtkJglDaBVs/preview).
    at AngularCompilerPlugin.getCompiledFile (/application/node_modules/@ngtools/webpack/src/angular_compiler_plugin.js:749:23)
    at plugin.done.then (/application/node_modules/@ngtools/webpack/src/loader.js:41:31)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)

我搜索了如何解决它,我读了写:

"paths": {
  "@ngx-lorem-ipsum/": [ "./node_modules/ngx-lorem-ipsum/lib/" ],
},

在tsconfig.json的末尾它应该是固定的。但编译仍然失败,同样的错误。

现在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"
    ],
    "module": "es2015",
    "baseUrl": "./",
    "paths": {
      "@ngx-lorem-ipsum/": [ "./node_modules/ngx-lorem-ipsum/lib/" ],
    },
  }
}

如何解决TypeScript编译错误中的缺失?

  • Angular CLI:6.1.5
  • 节点:8.9.4
  • 操作系统:darwin x64
  • Angular:6.1.4
  • NGX-LOREM营销:^ 0.1.1
答案

最后,感谢Mikhail Burshteyn的评论,我解决了它。我必须使用include标记将库目录添加到tsconfig.json。

现在tsconfig.json看起来像这样:

{
  "compileOnSave": false,
  "include": [
    "src/**/*.ts",
    "node_modules/ngx-lorem-ipsum/**/*.ts"
    ],
  "compilerOptions": {
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es5",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2017",
      "dom"
    ],
    "module": "es2015",
    "baseUrl": "./",
    "paths": {
      "@ngx-lorem-ipsum/": [ "./node_modules/ngx-lorem-ipsum/lib/" ],
    },
  }
}

以上是关于更新角度4.4到6后,缺少TypeScript编译错误的主要内容,如果未能解决你的问题,请参考以下文章

从 5 到 6 的角度迁移后无法构建 - 找不到模块“打字稿”

更新到角度6后找不到app-root

如何解决“错误:TypeScript 编译中缺少 \src\main.ts”。

更新 OSX 命令行工具 6.3 后缺少 C++ 标头 <__debug>

TypeScript 编译中缺少 Angular5 :polyfills.ts & \main.ts

typescript 角度反应形式更新表单结构