我想按照 this answer 从 Angular5 迁移到 Angular6
我尝试执行这三个命令,将 .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。但它没有帮助:
Schema validation failed with the following errors: Data path "" should NOT have additional properties(project). Error: Schema validation failed with the following errors: Data path "" should NOT have additional properties(project). at MergeMapSubscriber._registry.compile.pipe.operators_1.concatMap.validatorResult [as project] (C:\projects\my-app\node_modules\@angular-devkit\core\src\workspace\workspace.js:173:42) at MergeMapSubscriber._tryNext (C:\projects\my-app\node_modules\rxjs\internal\operators\mergeMap.js:122:27) at MergeMapSubscriber._next (C:\projects\my-app\node_modules\rxjs\internal\operators\mergeMap.js:112:18) at MergeMapSubscriber.Subscriber.next (C:\projects\my-app\node_modules\rxjs\internal\Subscriber.js:103:18) at MergeMapSubscriber.notifyNext (C:\projects\my-app\node_modules\rxjs\internal\operators\mergeMap.js:141:26) at InnerSubscriber._next (C:\projects\my-app\node_modules\rxjs\internal\InnerSubscriber.js:30:21) at InnerSubscriber.Subscriber.next (C:\projects\my-app\node_modules\rxjs\internal\Subscriber.js:103:18) at MapSubscriber._next (C:\projects\my-app\node_modules\rxjs\internal\operators\map.js:92:26) at MapSubscriber.Subscriber.next (C:\projects\my-app\node_modules\rxjs\internal\Subscriber.js:103:18) at SwitchMapSubscriber.notifyNext (C:\projects\my-app\node_modules\rxjs\internal\operators\switchMap.js:122:26)
因此,我尝试运行 ng update @angular/core
,但出现此错误:
Workspace needs to be loaded before it is used.
我做错了什么?
最佳答案
您不能手动将文件 .angular-cli.json 重命名为 angular.json。他们有不同的模式,因此你的错误。
删除现有目录 node_modules。确保从项目的根目录运行 npm install @angular/cli
和 ng update @angular/cli
。如果未创建文件 angular.json,请阅读控制台上的输出 - 它应该会给您一些错误。
如果这没有帮助,只需使用 Angular CLI 6 生成一个新项目并将 src 目录和 Assets 从现有项目复制到新生成的项目中。
我在博客上写了我将 Angular 5 项目升级到 Angular 6 的经历:https://yakovfain.com/2018/05/16/how-i-migrated-a-dozen-of-projects-to-angular-6
关于json - 从 Angular 5 迁移到 Angular 6,angular.json 没有更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50667774/