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
The angular.json file at the root level of an Angular workspace provides workspace-wide and project-specific configuration defaults. These are used for build and development tools provided by the Angular CLI. Path values given in the configuration are relative to the root workspace directory.
A schematic is a template-based code generator that supports complex logic. It is a set of instructions for transforming a software project by generating or modifying code. Schematics are packaged into collections and installed with npm.
This folder contains your projects dependencies including Angular, autoprefixer, browserify, caniuse-lite, postcss and much more.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With