当我在Travis CI上测试我的Angular项目时,出现了两个异常:
$ 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.
错误消息非常令人困惑。我在谷歌上搜索了">Angular项目定义",但没有发现任何相关信息。
我查看了Angular CLIwiki,但是没有关于CCD_ 1和CCD_,更不用说">项目定义"的定义了。
我的Github项目:
https://github.com/donizyo/ng-dementor
我的开发环境:
$ 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
Travis CI的原始日志可以在这里找到。
更新1
我刚刚在我的电脑上安装了最新的Angular CLI(v7.0.4(,
$ 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)
并用它生成了一个新的项目CCD_ 3
当我在目录CCD_ 5中执行CCD_,一切都很顺利。Karma v3.0.0服务器启动,Chrome浏览器启动。
但是当我在目录CCD_ 7中执行CCD_,Angular CLI只提供了">测试命令需要在Angular项目中运行,但找不到项目定义。">
更新2
我更新了Angular CLI根据Angular Update Guide。现在我的开发环境是:
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
这个答案涵盖了Angular 6,但看起来你使用的是旧的Angular版本,所以它可能无法正常工作。你可以升级到6,详细信息如下:
https://blog.angular.io/version-6-of-angular-now-available-cc56b0efa7a4
所以无论如何,在Angular 6中,你会在angular.json
:中找到这些条目
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"MYPROJECT": {
// more stuff
}
},
// more stuff
"defaultProject": "MYPROJECT"
}
要测试此项目,您可以运行:
ng test
或
ng test MYPROJECT
如果你运行这个:
ng test --help
它将提供一些关于如何将该命令用于特定版本的Angular的反馈。
另请参阅此处,但这是特定于Angular 6的。
另请参阅Angular Cli错误:serve命令需要在Angular项目中运行,但找不到项目定义
此外,您在travis上的全局安装与在本地机器上的安装相同吗?
如果您需要在全球范围内安装一些软件包,请将其添加到.travis.yml
文件中:
before_install:
- npm install -g your-package-name