Error: Local workspace file ('angular.json

2019-01-03 21:23发布

I have travis-ci integrated with my GitHub account (https://github.com/pradeep0601/Angular5-Router-App).

When I updated @angular/cli version from 1.7.4 to 6.0.0-rc.3, the build started failing with an error:

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 snippet to better understand the running environment:

    "@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",

19条回答
We Are One
2楼-- · 2019-01-03 21:40

With recent version, without --migrate-only I got the repo updated.

I did ng update

The Angular CLI configuration format has been changed, and your existing configuration can be updated automatically by running the following command:

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)
查看更多
相关推荐>>
3楼-- · 2019-01-03 21:41

I was getting the same error messages. It was a silly mistake on my end, I was not running ng serve in the directory where my Angular project is. Make sure you are in the correct directory (project directory) before running this command.

查看更多
迷人小祖宗
4楼-- · 2019-01-03 21:41

Well, I faced the same issue as soon as I updated my angular cli version.

Earlier I was using 1.7.4 and just now I upgraded it to angular cli 6.0.8.

To update Angular Cli global-

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

To update Angular Cli dev-

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

To fix audit issues after npm install:-

npm audit fix

To fix the issue related to "angular.json" :-

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

Hoping this will help you :)

查看更多
萌系小妹纸
5楼-- · 2019-01-03 21:42

Uninstall the old version of Angular cli, and install Angular CLI global:

Update Angular cli global package to the next version, "@angular/compiler-cli": "^6.0.0"

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

Generate a new project and default application by running the following command:

ng new my-project
cd my-project
ng serve
查看更多
啃猪蹄的小仙女
6楼-- · 2019-01-03 21:45

It works for me:

Delete folder node_modules

Run command: npm install

( If it does not work for the first time, repeat this 2 or 3 times, Its funny but it works for me. )

查看更多
等我变得足够好
7楼-- · 2019-01-03 21:46

Just run ng update @angular/cli in your console. You might find some vulnerabilities after running the command (if using npm), but then just runnpm audit fix in the console to fix them. This command will scan the project for any vulnerabilities and it will also fix compatibility issues by installing updates to these dependencies. If you do not wish to auto fix these vulnerabilities immediately, you can perform a Dry Run: by running npm audit fix --dry-run -json in the console. This will give you an idea of what the command npm audit fix will do, in the form of json in the console.

查看更多
登录 后发表回答