in-memory-data.service.ts отсутствует в компиляции TypeScript - PullRequest
0 голосов
/ 06 августа 2020

Пройдя через Anghular учебное пособие по использованию HTTP-запросов в https://angular.io/tutorial/toh-pt6, я дошел до этого момента:

Создайте класс 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 / src / app / in-memory-data.service.ts отсутствует в компиляции TypeScript. Убедитесь, что он находится в вашем tsconfig через свойство 'files' или 'include'. в AngularCompilerPlugin.getCompiledFile (/home/nart/Documents/MachineTranslation/open-translate/node_modules/@ngtools/webpack/src/angular_compiler_plugin.js:935:23) в / home / nart / Documents / MachineTranslation / open /node_modules/@ngtools/webpack/src/loader.js:42:31 в runMicrotasks () в processTicksAndRejection (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.spe c. 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"
  ]
}

Ответы [ 2 ]

0 голосов
/ 13 августа 2020

Добавляли ли вы свою услугу к провайдерам?

@NgModule({
  imports: [ ... ],
  declarations: [ ... ],
  providers: [
    InMemoryDataService
  ]
0 голосов
/ 13 августа 2020

Столкнулся с той же проблемой. В конце концов, это решило просто повторный запуск ng serve (точнее, повторное нажатие «Run 'Angular CLI Server» на PyCharm.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...