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

2024-04-02

浏览 Angular 教程,了解如何在中使用 http 请求https://angular.io/tutorial/toh-pt6 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 (内部/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"
  ]
}

面临着同样的问题。最后,解决这个问题的方法只是重新运行 ngserve(更准确地说,再次在 PyCharm 上单击“运行‘Angular CLI Server’”。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

TypeScript 编译中缺少 in-memory-data.service.ts 的相关文章

随机推荐