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

Angular CliTravis CiPackage lock.json

Angular Cli Problem Overview


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

Angular Cli Solutions


Solution 1 - Angular Cli

I just had the same problem.

It's related to release v6.0.0-rc.2, https://github.com/angular/angular-cli/releases:

> New configuration format. The new file can be found at angular.json (but .angular.json is also accepted). Running ng update on a CLI 1.7 project will move you to the new configuration.

I needed to execute:

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

This removed .angular-cli.json and created angular.json.

If this leads to your project using 1.7.4, install v6 locally:

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

And try once again to update your project with:

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

Solution 2 - Angular Cli

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.

Solution 3 - Angular Cli

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)

Solution 4 - Angular Cli

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

Solution 5 - Angular Cli

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

Solution 6 - Angular Cli

Try using the below command:

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

It will perform the below

  • Updating karma configuration

  • Updating configuration

  • Removing old config file (.angular-cli.json)

  • Writing config file (angular.json)

Pls note that the above command should be run in the folder where you have file .angular-cli.json and it will be then replaced by angular.json.

Solution 7 - Angular Cli

If you don't know the version ,current project has been made, you can omit --from command and type --migrate-only

> ng update @angular/cli --migrate-only

Solution 8 - Angular Cli

If all sorts of updating commando's won't do it. Try deleting package-lock.json. And then run npm install. Did the trick for me after going through tons of update commando's.

Solution 9 - Angular Cli

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. )

Solution 10 - Angular Cli

Check your folder structure where you are executing the command, you should run the command 'ng serve' where there should be a angular.json file in the structure.

angular.json file will be generated by default when we run the command

npm install -g '@angular/cli' ng new Project_name then cd project_folder then, run ng serve. it worked for me

Solution 11 - Angular Cli

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.

Solution 12 - Angular Cli

I had the same problem, and what I did that works for me was:

  1. Inside package.json file, update the Angular CLI version to my desired one:

     "devDependencies": { ...
       "@angular/cli": "^6.0.8",
       ...
     }
    
  2. Delete the node_modules folder, in order to clean the project before update the dependencies with:

     npm install
    
     ng update @angular/cli
    
  3. Try to build again my project (the last and successful attempt)

     ng build --prod
    

Solution 13 - Angular Cli

For me what worked was creating a new Angular project and just copied the angular.json file in the project that had a problem due to the fact that the angular.json file was missing.

Solution 14 - Angular Cli

For me the problem was because of global @angular/cli version and @angular/compiler-cli were different. Look into package.json.

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

And if they don’t match, update or downgrade one of them.

Solution 15 - Angular Cli

I also faced same issue and i just executed below command.

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

It simply delete angular-cli.json and create angular.json. You can find this in logs.

Once you start execution. You will be able to see below logs in your terminal.

        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)

Solution 16 - Angular Cli

Just check your directory, you must run "ng serve " on the same directory where you have created the project.

So, first enter in your project directory.

Solution 17 - Angular Cli

Check out this link to migrate from Angular 5.2 to 6. https://update.angular.io/

Upgrading to version 8.9 worked for me. enter image description here

Solution 18 - Angular Cli

For me, the issue was that I have an angular project folder inside a rails project folder, and I ran all the angular update commands in the rails parent folder rather than the actual angular folder.

Solution 19 - Angular Cli

I was having this error message inside a docker container. I resolved it adding:

WORKDIR /usr/src

to Dockerfile.

Solution 20 - Angular Cli

I had the same problem and found that there was no package.json in my project (but only the package-lock.json). I then

  1. restored the package.json from source control
  2. uninstalled the global and local angular-cli versions (like the instruction says)
  3. followed the standard upgrade procedure

..and all worked out fine. Took a while to figure it out, but that did it for me.

Solution 21 - Angular Cli

~/Desktop $ ng serve

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

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

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)

> This is because I haven't choose the Angular project directory. >

It should be like: > ~/Desktop/angularproject $ ng serve

Solution 22 - Angular Cli

I was trying to set my Ionic 4 app to run as a pwa. When I run the command:

ng add @angular/pwa

...got the error message. After some try and error I discovered that when my project was created the start command was wrong. I was using an Ionic 3 version:

ionic start myApp tabs --type=ionic-angular

And the correct is:

ionic start myApp tabs --type=angular

with no 'ionic-' in type. This solved the error.

Solution 23 - Angular Cli

For people who have simply cloned a project and trying to run it, you need to run npm install first. I totally forgot to run this and was simply running ng serve before installing node modules.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionPradeepView Question on Stackoverflow
Solution 1 - Angular CliLenniView Answer on Stackoverflow
Solution 2 - Angular CliDRGView Answer on Stackoverflow
Solution 3 - Angular CliSundaraView Answer on Stackoverflow
Solution 4 - Angular CliVikash PandeyView Answer on Stackoverflow
Solution 5 - Angular CliSanjay kumarView Answer on Stackoverflow
Solution 6 - Angular CliTechSinghView Answer on Stackoverflow
Solution 7 - Angular Clivipin cpView Answer on Stackoverflow
Solution 8 - Angular CliDennis GadomskiView Answer on Stackoverflow
Solution 9 - Angular CliShubham VermaView Answer on Stackoverflow
Solution 10 - Angular CliVinay ReddyView Answer on Stackoverflow
Solution 11 - Angular CliEZCityView Answer on Stackoverflow
Solution 12 - Angular CliJuan MonsalveView Answer on Stackoverflow
Solution 13 - Angular CliMathews MusukumaView Answer on Stackoverflow
Solution 14 - Angular CliFilip MolcikView Answer on Stackoverflow
Solution 15 - Angular CliAmbuj KhannaView Answer on Stackoverflow
Solution 16 - Angular Clisatywan kumarView Answer on Stackoverflow
Solution 17 - Angular CliragaView Answer on Stackoverflow
Solution 18 - Angular CliNiekView Answer on Stackoverflow
Solution 19 - Angular CliNaeView Answer on Stackoverflow
Solution 20 - Angular CliStefan de GrootView Answer on Stackoverflow
Solution 21 - Angular CliManu R SView Answer on Stackoverflow
Solution 22 - Angular CliNowdeenView Answer on Stackoverflow
Solution 23 - Angular CliSagar KhatriView Answer on Stackoverflow