Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

in-memory-data.service.ts is missing from the TypeScript compilation

Tags:

angular

Walking through Anghular tuturial on how to use http requests in https://angular.io/tutorial/toh-pt6, I got to this point:

Generate the class src/app/in-memory-data.service.ts with the following command: ng generate service InMemoryData

Then I came across this issue, any idea how to solve it?

Failed to compile. ./src/app/in-memory-data.service.ts Module build failed (from ./node_modules/@ngtools/webpack/src/index.js): Error: /home/nart/Documents/MachineTranslation/open-translate/src/app/in-memory-data.service.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property. at AngularCompilerPlugin.getCompiledFile (/home/nart/Documents/MachineTranslation/open-translate/node_modules/@ngtools/webpack/src/angular_compiler_plugin.js:935:23) at /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)

Here is the 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"
    }
]
}

Here is the 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"
  ]
}

Here is the 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"
    ]
  }
}

Here is 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"
  ]
}
like image 529
Daniel abzakh Avatar asked Jan 24 '23 20:01

Daniel abzakh


2 Answers

Was facing the same issue. In the end, what solved it was just re-running ng serve (more precisely, clicking "Run 'Angular CLI Server" on PyCharm again.

like image 70
Wyzzard123 Avatar answered Jan 27 '23 08:01

Wyzzard123


Did you add your service to the providers?

@NgModule({
  imports: [ ... ],
  declarations: [ ... ],
  providers: [
    InMemoryDataService
  ]
like image 36
Dmitry Grinko Avatar answered Jan 27 '23 10:01

Dmitry Grinko