TypeScript 编译中缺少 in-memory-data.service.ts

Dan*_*akh 4 angular

通过 Anghular tuturial 如何在https://angular.io/tutorial/toh-pt6 中使用 http 请求 ,我到了这一点:

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

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

编译失败。./src/app/in-memory-data.service.ts 模块构建失败(来自 ./node_modules/@ngtools/webpack/src/index.js):错误:/home/nart/Documents/MachineTranslation/open-translate TypeScript 编译中缺少 /src/app/in-memory-data.service.ts。请通过“文件”或“包含”属性确保它在您的 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 at runMicrotasks () at 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"
    }
]
}
Run Code Online (Sandbox Code Playgroud)

这是 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"
  ]
}
Run Code Online (Sandbox Code Playgroud)

这是 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"
    ]
  }
}
Run Code Online (Sandbox Code Playgroud)

这是 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"
  ]
}
Run Code Online (Sandbox Code Playgroud)

小智 7

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