angular - 从 angular4 升级到 angular 5 "test.ts is missing from the TypeScript compilation"后 npm 测试失败

标签 angular typescript angular-upgrade

我按照此处提到的步骤将我的应用程序从 angular4 升级到 angular 5:https://update.angular.io/

我可以毫无问题地运行 ng-serve 、 ng build 等。

但是 ng 测试(npm 测试)失败并出现错误:

\src\test.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property.

我尝试了足够多的谷歌搜索并解决了这个问题,但它们似乎都没有用。

按照这里的建议, https://stackoverflow.com/a/48798373/2754029 我尝试在 angular-cli.json 和 tsconfig.json 中添加配置,但这不起作用。

任何人都可以在这里帮助我。如果您需要这方面的更多信息,请告诉我。

最佳答案

在我的例子中,那是因为 ng test 使用 tsconfig.spec.json,而不是 tsconfig.json。检查您的 tsconfig.spec.json 并且您的 test.ts 列在 files 部分中。

您可以在 angular.json 的以下部分查看/更改要使用的 tsconfig。

{
  "projects": {
    "YOUR_PROJECT": {
      "architect": {
        "test": {
          "options": {
            "tsConfig": "tsconfig.spec.json", // <---- See here
            "karmaConfig": "src/YOUR_PROJECT/karma.conf.js"

参见 https://angular.io/guide/file-structure#default-app-project-files想要查询更多的信息。希望对您有所帮助。

关于angular - 从 angular4 升级到 angular 5 "test.ts is missing from the TypeScript compilation"后 npm 测试失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50851280/

相关文章:

typescript - `getBoundingClientRect()` 返回什么类型?

angular - 测试 UpgradeComponent 抛出 NullInjectorError : No provider for $injector! 错误

javascript - 从 webapp 启动本地 exe

angular - !x 相当于 (x===undefined || x.length===0)

javascript - FormBuilder - 自定义验证器 - 许多字段和 promise

typescript - 为什么我的 Sequelize/Typescript 函数会出现 "Two different types with this name exist, but they are unrelated."错误?

reactjs - Typescript Redux Thunk(类型)

Angular 2 自定义输入组件验证(新表单 api)

angularjs - 如何在 ngx-bootstrap Modal 中使用 angularjs 升级组件?

angularjs - 当浏览器选项卡在后台时,Angular/AngularJS 升级应用程序无响应