【问题标题】:Migrating from Angular5 to Angular6, angular.json is not updated从 Angular5 迁移到 Angular6,angular.json 没有更新
【发布时间】:2018-11-13 00:47:35
【问题描述】:

我想从 Angular5 迁移到 Angular6,跟随 this answer

我尝试执行这三个命令,将 .angular-cli.json 更新为 angular.json

npm install -g @angular/cli
npm install @angular/cli
ng update @angular/cli

很遗憾,仍然没有 angular.json。如果我尝试运行ng serve,我会收到此错误:

Local workspace file ('angular.json') could not be found.

所以我将 .angular-cli.json 重命名为 angular.json。但这并没有帮助:

架构验证失败,出现以下错误:数据路径“” 不应该有额外的属性(项目)。错误:架构 验证失败,出现以下错误:数据路径“”不应该 有额外的属性(项目)。 在 MergeMapSubscriber._registry.compile.pipe.operators_1.concatMap.validatorResult [作为项目] (C:\projects\my-app\node_modules\@angular-devkit\core\src\workspace\workspace.js:173:42) 在 MergeMapSubscriber._tryNext (C:\projects\my-app\node_modules\rxjs\internal\operators\mergeMap.js:122:27) 在 MergeMapSubscriber._next (C:\projects\my-app\node_modules\rxjs\internal\operators\mergeMap.js:112:18) 在 MergeMapSubscriber.Subscriber.next (C:\projects\my-app\node_modules\rxjs\internal\Subscriber.js:103:18) 在 MergeMapSubscriber.notifyNext (C:\projects\my-app\node_modules\rxjs\internal\operators\mergeMap.js:141:26) 在 InnerSubscriber._next (C:\projects\my-app\node_modules\rxjs\internal\InnerSubscriber.js:30:21) 在 InnerSubscriber.Subscriber.next (C:\projects\my-app\node_modules\rxjs\internal\Subscriber.js:103:18) 在 MapSubscriber._next (C:\projects\my-app\node_modules\rxjs\internal\operators\map.js:92:26) 在 MapSubscriber.Subscriber.next (C:\projects\my-app\node_modules\rxjs\internal\Subscriber.js:103:18) 在 SwitchMapSubscriber.notifyNext (C:\projects\my-app\node_modules\rxjs\internal\operators\switchMap.js:122:26)

因此我尝试运行ng update @angular/core,但出现此错误:

工作区在使用前需要加载。

我做错了什么?

【问题讨论】:

  • 它要求angular.json,而不是.angular.json
  • 检查 package.json 中的版本是否更新。您是否也尝试过重新加载工作区,尤其是如果您使用 VSC 作为编辑器。
  • 我使用notepad++作为编辑器。即使文件名没有点,我也会收到 Workspace needs to be loaded 错误
  • 我认为您不需要手动将文件名 .angular.cli.json 更改为 angular.json。一旦你更新并且它自动成功,配置应该从 .angular.cli.json 迁移到 angular.json。检查 package.json 中的版本是否更新并运行一次 npm install。这可以为您提供一些帮助 - Angular Update
  • 没有提到改文件名的地方。但即使使用新名称,我也会收到 Workspace needs to be loaded 错误

标签: json node.js angular angular-cli


【解决方案1】:

您不能手动将文件 .angular-cli.json 重命名为 angular.json。他们有不同的架构,因此你的错误。

删除现有目录 node_modules。确保从项目的根目录运行 npm install @angular/cling update @angular/cli。如果未创建文件 angular.json,请阅读控制台上的输出 - 它应该会给您一些错误。

如果这没有帮助,只需使用 Angular CLI 6 生成一个新项目,然后将现有项目中的 src 目录和资产复制到新生成的项目中。

我在这里写了一篇关于我将 Angular 5 项目升级到 Angular 6 的经验的博客:https://yakovfain.com/2018/05/16/how-i-migrated-a-dozen-of-projects-to-angular-6

【讨论】:

    猜你喜欢
    • 2018-10-18
    • 2019-03-30
    • 2019-01-03
    • 2019-07-28
    • 2020-02-17
    • 1970-01-01
    • 2012-11-29
    • 2010-09-09
    • 1970-01-01
    相关资源
    最近更新 更多