5

When I test my Angular project on Travis-CI, two exceptions emerged:

$ ng test
The test command requires to be run in an Angular project, but a project definition could not be found.
The command "ng test" exited with 1.

$ ng e2e
The e2e command requires to be run in an Angular project, but a project definition could not be found.
The command "ng e2e" exited with 1.

The error message is pretty confusing. I googled about "Angular project definition", but nothing relevant is found.

I checked out Angular CLI wiki, but there is no useful information about ng test and ng e2e, not to mention the definition of "project definition".


My Github project:

https://github.com/donizyo/ng-dementor

My development environment:

$ ng version
Angular CLI: 7.0.3
Node: 11.1.0
OS: linux x64
Angular: 5.2.11
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router
Package                      Version
------------------------------------------------------
@angular-devkit/architect    0.10.3
@angular-devkit/core         7.0.3
@angular-devkit/schematics   7.0.3
@angular/cli                 7.0.3
@schematics/angular          7.0.3
@schematics/update           0.10.3
rxjs                         5.5.12
typescript                   2.5.3

Raw log of Travis-CI can be found here.


UPDATE 1

I just installed the lastest Angular CLI (v7.0.4) on my PC,

$ ng version
Angular CLI: 7.0.4
Node: 8.9.3
OS: win32 ia32
Angular: <error>
... animations, cli, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router
Package                      Version
------------------------------------------------------
@angular-devkit/architect    0.10.4 (cli-only)
@angular-devkit/core         7.0.4 (cli-only)
@angular-devkit/schematics   7.0.4 (cli-only)
@schematics/angular          7.0.4 (cli-only)
@schematics/update           0.10.4 (cli-only)
rxjs                         6.3.3 (cli-only)
typescript                   3.1.3 (cli-only)

and generated a new project testprj with it.

When I execute ng test in directory My Projects/testprj/, everything goes fine. Karma v3.0.0 server was started, Chrome browser was launched.

However when I execute ng test in directory My Projects/ng-dementor/, Angular CLI gives me nothing but "The test command requires to be run in an Angular project, but a project definition could not be found."


UPDATE 2

I updated my Angular CLI according to Angular Update Guide. Now my develop environment is:

Angular CLI: 7.0.4
Node: 8.9.3
OS: win32 ia32
Angular: 5.2.11
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.10.4
@angular-devkit/build-angular     0.10.4
@angular-devkit/build-optimizer   0.10.4
@angular-devkit/build-webpack     0.10.4
@angular-devkit/core              7.0.4
@angular-devkit/schematics        7.0.4
@angular/cli                      7.0.4
@ngtools/webpack                  7.0.4
@schematics/angular               7.0.4
@schematics/update                0.10.4
rxjs                              5.5.12
typescript                        2.5.3
webpack                           4.19.1
KaiserKatze
  • 1,521
  • 2
  • 20
  • 30

1 Answers1

3

This answer covers Angular 6, but it looks like you are using an older Angular version so this might not work exactly as is. You could upgrade to 6 as detailed here:

https://blog.angular.io/version-6-of-angular-now-available-cc56b0efa7a4

So anyway in Angular 6 you will find these entries in angular.json:

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "MYPROJECT": {
      // more stuff
    }
  },
  // more stuff
  "defaultProject": "MYPROJECT"
}

To test this project you can run:

ng test

OR

ng test MYPROJECT

If you run this:

ng test --help

It will provide some feedback on how to use the command for your specific version of Angular.

Also see here but this is Angular 6 specific.

See also Angular Cli Error: The serve command requires to be run in an Angular project, but a project definition could not be found

Also, are your global installs on travis the same as on your local machine?

If you need some packages installed globally, add this to your .travis.yml file:

before_install:
- npm install -g your-package-name
danday74
  • 52,471
  • 49
  • 232
  • 283
  • Sir, your link to _blog.angular.io_ yields 504 error. I don't know what's the content of that page. Could you please help me with that? – KaiserKatze Nov 03 '18 at 06:06
  • try now, it didn't seem to like the # in the URL which was an anchor link, I've removed the anchor link, the section you want is titled ng update, scroll down a little – danday74 Nov 03 '18 at 06:10
  • 1
    After I followed [Angular Update Guide](https://update.angular.io/) step by step, `ng test` runs correctly now, thx. – KaiserKatze Nov 03 '18 at 08:22