【问题标题】:in-memory-data.service.ts is missing from the TypeScript compilationTypeScript 编译中缺少 in-memory-data.service.ts
【发布时间】:2020-11-26 13:41:50
【问题描述】:

浏览 Anghular tuturial 如何使用 http 请求 https://angular.io/tutorial/toh-pt6,到此为止:

使用以下命令生成类 src/app/in-memory-data.service.ts: ng 生成服务 InMemoryData

然后我遇到了这个问题,知道如何解决吗?

编译失败。 ./src/app/in-memory-data.service.ts 模块构建失败(来自 ./node_modules/@ngtools/webpack/src/index.js): 错误:TypeScript 编译中缺少 /home/nart/Documents/MachineTranslation/open-translate/src/app/in-memory-data.service.ts。请通过 'files' 或 'include' 属性确保它在您的 tsconfig 中。 在 AngularCompilerPlugin.getCompiledFile (/home/nart/Documents/MachineTranslation/open-translate/node_modules/@ngtools/webpack/src/angular_compiler_plugin.js:935:23) 在/home/nart/Documents/MachineTranslation/open-translate/node_modules/@ngtools/webpack/src/loader.js:42:31 在 runMicrotasks () 在 processTicksAndRejections (internal/process/task_queues.js:97:5)

这里是 tsconfig.json

/*
  This is a "Solution Style" tsconfig.json file, and is used by editors and TypeScript’s language server to improve development experience.
  It is not intended to be used to perform a compilation.

  To learn more about this file see: https://angular.io/config/solution-tsconfig.
*/
{
  "files": [],
  "references": [
    {
      "path": "./tsconfig.app.json"
    },
    {
      "path": "./tsconfig.spec.json"
    }
]
}

这里是 tsconfig.app.json

/* To learn more about this file see: https://angular.io/config/tsconfig. */
{
  "extends": "./tsconfig.base.json",
  "compilerOptions": {
    "outDir": "./out-tsc/app",
    "types": []
  },
  "files": [
    "src/main.ts",
    "src/polyfills.ts"
  ],
  "include": [
    "src/**/*.d.ts"
  ]
}

这里是 tsconfig.base.json

/* To learn more about this file see: https://angular.io/config/tsconfig. */
{
  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": "./",
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "downlevelIteration": true,
    "experimentalDecorators": true,
    "moduleResolution": "node",
    "importHelpers": true,
    "target": "es2015",
    "module": "es2020",
    "lib": [
      "es2018",
      "dom"
    ]
  }
}

这里是 tsconfig.spec.json

/* To learn more about this file see: https://angular.io/config/tsconfig. */
{
  "extends": "./tsconfig.base.json",
  "compilerOptions": {
    "outDir": "./out-tsc/spec",
    "types": [
      "jasmine"
    ]
  },
  "files": [
    "src/test.ts",
    "src/polyfills.ts"
  ],
  "include": [
    "src/**/*.spec.ts",
    "src/**/*.d.ts"
  ]
}

【问题讨论】:

  • 请在此处分享您的 ts 配置文件,以便我们了解发生了什么
  • 我已经添加了这些文件,我假设演示应该开箱即用,只需按照步骤操作即可。
  • 我在学习 Angular 教程时遇到了同样的问题

标签: angular


【解决方案1】:

面临同样的问题。最后,解决它的只是重新运行 ng serve (更准确地说,再次单击 PyCharm 上的“Run 'Angular CLI Server”。

【讨论】:

  • 我也是这样。感谢您发布答案!
【解决方案2】:

您是否将您的服务添加到提供者?

@NgModule({
  imports: [ ... ],
  declarations: [ ... ],
  providers: [
    InMemoryDataService
  ]

【讨论】:

    猜你喜欢
    • 2019-01-05
    • 1970-01-01
    • 2018-10-01
    • 2018-08-12
    • 1970-01-01
    • 1970-01-01
    • 2021-02-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多