ng add ng-alain 遇到错误:Cannot read property 'build' of undefined

按照文档开始使用步骤遇到错误无法继续

使用ng add ng-alain添加模块,遇到错误进行下一步学习,完整的输出信息:

$ ng add ng-alain
Installing packages for tooling via npm.
npm WARN ng-alain@1.4.0 requires a peer of @angular-devkit/core@^0.6.1 but none is installed. You must install peer dependencies yourself.
npm WARN ng-alain@1.4.0 requires a peer of @angular-devkit/schematics@^0.6.1 but none is installed. You must install peer dependencies yourself.
npm WARN ng-alain@1.4.0 requires a peer of @schematics/angular@^0.6.1 but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

+ ng-alain@1.4.0
updated 1 package in 17.296s
Installed packages for tooling via npm.
Cannot read property 'build' of undefined

接着运行教程中的下一行命令ng server就会报错:

$ ng server
The specified command ("server") is invalid. For a list of available options,
run "ng help".
Did you mean "serve"?

angular版本信息:

Angular CLI: 6.2.1
Node: 8.11.2
OS: win32 x64
Angular: 6.1.7
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.8.1
@angular-devkit/build-angular     0.8.1
@angular-devkit/build-optimizer   0.8.1
@angular-devkit/build-webpack     0.8.1
@angular-devkit/core              0.8.1
@angular-devkit/schematics        0.8.1
@angular/cli                      6.2.1
@ngtools/webpack                  6.2.1
@schematics/angular               0.8.1
@schematics/update                0.8.1
rxjs                              6.2.2
typescript                        2.9.2
webpack                           4.17.2

初次使用,不太懂怎么处理,还请同学们帮帮忙,十分感谢。

阅读 4.8k
1 个回答

欢迎加入开源社区!在这个社区里,就是会出现各种不匹配,有的时候需要等大佬们发新版来互相匹配,有的时候耐不性子,亲自上场打怪,开pull request帮大佬们除妖也是一个办法。

你这个问题导致的原因是:Angular版本太超前了,而ng-alain版本还没有跟上导致的。注意看错误信息:

npm WARN ng-alain@1.4.0 requires a peer of @angular-devkit/core@^0.6.1

ng-alian说它需要@angular-devkit/core@^0.6.1,而你提供的版本是:

@angular-devkit/core              0.8.1

所以目前有3个办法:

  1. 坐等ng-alain发新版支持0.8.14个小时前ng-alain刚刚发表1.4.2版本,查看它的package.json文件,你会发现,他们刚刚开始支持0.8.0。而它支持的Angular版本仅仅只是6.1.0,而你安装的Angular版本是6.1.7,所以目前还是匹配不上。或者你也可以把他们的源代码下载下来,改造成支持Angular 6.1.7的再上传上去,看他们是否愿意接受。
  2. 改造自己的package.json文件,把里面所有写着6.1.7的地方,改成6.1.0或者更低,然后重新npm install
  3. 不手动修改package.json,而是重新安装低版本的angular cli,然后重新生成项目:
npm uninstall -g angular-cli
npm cache clean
npm install -g angular-cli@6.1.0
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进