TypeScript编译中缺少in-memory-data.service.ts [英] in-memory-data.service.ts is missing from the TypeScript compilation

查看:75
本文介绍了TypeScript编译中缺少in-memory-data.service.ts的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Anghular教程中逐步了解如何使用http请求 https://angular.io/tutorial/toh-pt6 ,我明白了这一点:

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

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

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?

无法编译../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.请通过文件"或包含"属性确保它在您的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)

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)

这是tsconfig.json

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"
    }
]
}

这是tsconfig.app.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"
  ]
}

这是tsconfig.base.json

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"
    ]
  }
}

这是tsconfig.spec.json

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"
  ]
}

推荐答案

面临相同的问题.最后,解决问题的方法只是重新运行ng serve(更准确地说,再次单击PyCharm上的运行'Angular CLI服务器".

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.

这篇关于TypeScript编译中缺少in-memory-data.service.ts的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆