196

我已travis-ci与我的 GitHub 帐户(https://github.com/pradeep0601/Angular5-Router-App)集成。

当我将@angular/cli版本从 1.7.4 更新到 6.0.0-rc.3 时,构建开始失败并出现错误:

Local workspace file ('angular.json') could not be found.
Error: Local workspace file ('angular.json') could not be found.
    at WorkspaceLoader._getProjectWorkspaceFilePath (/home/travis/build/pradeep0601/Angular5-Router-App/node_modules/@angular/cli/models/workspace-loader.js:37:19)
    at WorkspaceLoader.loadWorkspace (/home/travis/build/pradeep0601/Angular5-Router-App/node_modules/@angular/cli/models/workspace-loader.js:24:21)
    at TestCommand._loadWorkspaceAndArchitect (/home/travis/build/pradeep0601/Angular5-Router-App/node_modules/@angular/cli/models/architect-command.js:177:32)
    at TestCommand.<anonymous> (/home/travis/build/pradeep0601/Angular5-Router-App/node_modules/@angular/cli/models/architect-command.js:45:25)
    at Generator.next (<anonymous>)
    at /home/travis/build/pradeep0601/Angular5-Router-App/node_modules/@angular/cli/models/architect-command.js:7:71
    at new Promise (<anonymous>)
    at __awaiter (/home/travis/build/pradeep0601/Angular5-Router-App/node_modules/@angular/cli/models/architect-command.js:3:12)
    at TestCommand.initialize (/home/travis/build/pradeep0601/Angular5-Router-App/node_modules/@angular/cli/models/architect-command.js:44:16)
    at /home/travis/build/pradeep0601/Angular5-Router-App/node_modules/@angular/cli/models/command-runner.js:100:23

package.json 片段以更好地了解运行环境:

    "@angular/cli": "6.0.0-rc.3",
    "@angular/compiler-cli": "^5.2.0",
    "@angular/language-service": "^5.2.0",
    "@types/jasmine": "~2.8.3",
    "@types/jasminewd2": "~2.0.2",
4

23 回答 23

334

我只是有同样的问题。

它与版本 v6.0.0-rc.2 有关,https ://github.com/angular/angular-cli/releases :

新的配置格式。可以在 angular.json 中找到新文件(但也接受 .angular.json)。在 CLI 1.7 项目上运行 ng update 会将您移至新配置。

我需要执行:

ng update @angular/cli --migrate-only --from=1.7.4

这删除.angular-cli.json并创建了angular.json.

如果这导致您的项目使用 1.7.4,请在本地安装 v6:

npm install --save-dev @angular/cli@v6.0.0-rc.4

并再次尝试更新您的项目:

ng update @angular/cli --migrate-only --from=1.7.4
于 2018-04-13T07:45:21.953 回答
78

我收到了同样的错误信息。对我来说这是一个愚蠢的错误,我没有ng serve在我的 Angular 项目所在的目录中运行。在运行此命令之前,请确保您位于正确的目录(项目目录)中。

于 2018-05-11T01:25:56.197 回答
37

使用最新版本,--migrate-only我没有更新 repo。

更新了

Angular CLI 配置格式已更改,您现有的配置可以通过运行以下命令自动更新:

ng update @angular/cli
            Updating karma configuration
            Updating configuration
            Removing old config file (.angular-cli.json)
            Writing config file (angular.json)
            Some configuration options have been changed, please make sure to update any npm scripts which you may have modified.
DELETE .angular-cli.json
CREATE angular.json (3684 bytes)
UPDATE karma.conf.js (1040 bytes)
UPDATE src/tsconfig.spec.json (322 bytes)
UPDATE package.json (1340 bytes)
UPDATE tslint.json (3140 bytes)
于 2018-05-09T06:00:08.973 回答
21

好吧,我一更新我的angular cli版本就遇到了同样的问题。

早些时候我使用的是 1.7.4,现在我将它升级到angular cli 6.0.8.

要全局更新 Angular Cli:

npm uninstall -g angular-cli
npm cache clean 
npm install -g @angular/cli@latest

要更新 Angular Cli 开发人员:

npm uninstall --save-dev angular-cli
npm install --save-dev @angular/cli@latest
npm install

在 npm install 后修复审计问题:

npm audit fix

要解决与“angular.json”相关的问题:

ng update @angular/cli --migrate-only --from=1.7.4
于 2018-06-22T07:29:23.937 回答
17

卸载旧版本的 Angular cli,并安装 Angular CLI 全局:

将 Angular cli 全局包更新到下一个版本,“@angular/compiler-cli”:“^6.0.0”

npm uninstall -g @angular/cli
npm cache verify
npm install -g @angular/cli@next

通过运行以下命令生成一个新项目和默认应用程序:

ng new my-project
cd my-project
ng serve
于 2018-05-05T18:49:49.150 回答
10

尝试使用以下命令:

ng update @angular/cli --migrate-only --from=1.7.4

它将执行以下操作

  • 更新业力配置

  • 更新配置

  • 删除旧的配置文件 (.angular-cli.json)

  • 编写配置文件(angular.json)

请注意,上面的命令应该在你有文件的文件夹中运行。angular-cli.json然后它将被替换为angular.json.

于 2018-06-10T04:27:59.480 回答
9

如果你不知道版本,当前项目已经制作,你可以省略--from命令和类型--migrate-only

ng update @angular/cli --migrate-only

于 2018-06-09T06:28:43.397 回答
7

如果各种更新突击队都不会这样做。尝试删除package-lock.json。然后运行​​npm install。在经历了大量的更新突击队之后,为我做了诀窍。

于 2018-05-21T11:51:42.343 回答
4

这个对我有用:

删除文件夹 node_modules

运行命令: npm install

(如果第一次不起作用,重复2或3次,这很有趣,但对我有用。)

于 2018-06-20T11:31:36.733 回答
3

检查您正在执行命令的文件夹结构,您应该运行命令“ng serve”,其中结构中应该有一个 angular.json 文件。

当我们运行命令时,默认会生成 angular.json 文件

npm install -g '@angular/cli' ng new Project_name 然后 cd project_folder 然后运行 ​​ng serve。它对我有用

于 2018-05-23T21:36:49.840 回答
3

只需在您的控制台中运行。 ng update @angular/cli运行命令后你可能会发现一些漏洞(如果使用 npm),然后只需在控制台中运行npm audit fix即可修复它们。此命令将扫描项目中的任何漏洞,它还将通过安装这些依赖项的更新来修复兼容性问题。如果您不希望立即自动修复这些漏洞,您可以执行试运行:通过在控制台中运行。 npm audit fix --dry-run -json这将使您了解命令npm audit fix将执行的操作,以控制台中的 json 形式。

于 2018-07-11T19:00:30.563 回答
3

我有同样的问题,我所做的对我有用的是:

  1. 在 package.json 文件中,将 Angular CLI 版本更新为我想要的版本:

    "devDependencies": { ...
      "@angular/cli": "^6.0.8",
      ...
    }
    
  2. 删除node_modules文件夹,以便在更新依赖项之前清理项目:

    npm install
    
    ng update @angular/cli
    
  3. 尝试再次构建我的项目(最后一次也是成功的尝试)

    ng build --prod
    
于 2018-07-23T19:13:10.867 回答
2

对我来说,工作是创建一个的Angular 项目,然后将 angular.json 文件复制到由于 angular.json 文件丢失而出现问题的项目中。

于 2018-08-17T08:44:50.023 回答
1

对我来说,问题是因为全局@angular/cli版本和@angular/compiler-cli不同。查看package.json

...
"@angular/cli": "6.0.0-rc.3",
"@angular/compiler-cli": "^5.2.0",
...

如果它们不匹配,更新或降级其中之一。

于 2018-07-12T09:34:38.323 回答
1

我也遇到了同样的问题,我只是在命令下执行。

ng update @angular/cli --migrate-only --from=1.6.4

它只是删除angular-cli.json和创建angular.json. 您可以在日志中找到它。

一旦你开始执行。您将能够在终端中看到以下日志。

        Updating karma configuration
        Updating configuration
        Removing old config file (.angular-cli.json)
        Writing config file (angular.json)
        Some configuration options have been changed, please make sure to update any                                     
        npm scripts which you may have modified.
        DELETE .angular-cli.json
        CREATE angular.json (3599 bytes)
        UPDATE karma.conf.js (962 bytes)
        UPDATE src/tsconfig.spec.json (324 bytes)
        UPDATE package.json (1405 bytes)
        UPDATE tsconfig.json (407 bytes)
        UPDATE tslint.json (3026 bytes)
于 2018-08-09T10:46:15.770 回答
1

只需检查您的目录,您必须在创建项目的同一目录上运行“ng serve”。

所以,首先进入你的项目目录。

于 2019-06-21T10:56:00.233 回答
0

查看此链接以从 Angular 5.2 迁移到 6。 https://update.angular.io/

升级到 8.9 版对我有用。 在此处输入图像描述

于 2018-06-19T23:05:33.607 回答
0

对我来说,问题是我在 rails 项目文件夹中有一个 angular 项目文件夹,并且我在 rails 父文件夹而不是实际的 angular 文件夹中运行了所有 angular update 命令。

于 2018-06-25T18:37:26.383 回答
0

我在 docker 容器中收到此错误消息。我解决了它添加:

WORKDIR /usr/src

到 Dockerfile。

于 2018-07-05T08:42:02.963 回答
0

我有同样的问题,发现我的项目中没有package.json(但只有package-lock.json)。我那时

  1. 从源代码管理中恢复了 package.json
  2. 卸载了全局和本地 angular-cli 版本(如指令所述)
  3. 遵循标准升级程序

..一切都很好。花了一段时间才弄清楚,但这对我有用。

于 2018-09-01T17:54:56.110 回答
0
~/Desktop $ ng serve

找不到本地工作区文件('angular.json')。

错误:找不到本地工作区文件('angular.json')。

at WorkspaceLoader._getProjectWorkspaceFilePath (/usr/lib/node_modules/@angular/cli/models/workspace-loader.js:37:19)
at WorkspaceLoader.loadWorkspace (/usr/lib/node_modules/@angular/cli/models/workspace-loader.js:24:21)
at ServeCommand._loadWorkspaceAndArchitect (/usr/lib/node_modules/@angular/cli/models/architect-command.js:180:32)
at ServeCommand.<anonymous> (/usr/lib/node_modules/@angular/cli/models/architect-command.js:47:25)
at Generator.next (<anonymous>)
at /usr/lib/node_modules/@angular/cli/models/architect-command.js:7:71
at new Promise (<anonymous>)
at __awaiter (/usr/lib/node_modules/@angular/cli/models/architect-command.js:3:12)
at ServeCommand.initialize (/usr/lib/node_modules/@angular/cli/models/architect-command.js:46:16)
at Object.<anonymous> (/usr/lib/node_modules/@angular/cli/models/command-runner.js:87:23)

这是因为我没有选择 Angular 项目目录。

它应该是这样的:

~/Desktop/angularproject $ ng 服务

于 2019-02-21T06:18:08.353 回答
0

我试图将我的 Ionic 4 应用程序设置为作为 pwa 运行。当我运行命令时:

ng add @angular/pwa

...收到错误消息。经过一些尝试和错误后,我发现创建项目时启动命令是错误的。我使用的是 Ionic 3 版本:

ionic start myApp tabs --type=ionic-angular

正确的是:

ionic start myApp tabs --type=angular

类型中没有“离子-”。这解决了错误。

于 2019-03-26T21:37:33.607 回答
0

对于那些只是克隆了一个项目并试图运行它的人,你需要先运行它npm install。我完全忘了运行它,只是ng serve在安装节点模块之前运行。

于 2020-02-28T06:21:20.047 回答