鍍金池/ 問(wèn)答/HTML5  網(wǎng)絡(luò)安全/ ng add ng-alain 遇到錯(cuò)誤:Cannot read propert

ng add ng-alain 遇到錯(cuò)誤:Cannot read property 'build' of undefined

按照文檔開(kāi)始使用步驟遇到錯(cuò)誤無(wú)法繼續(xù)

使用ng add ng-alain添加模塊,遇到錯(cuò)誤進(jìn)行下一步學(xué)習(xí),完整的輸出信息:

$ 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

接著運(yùn)行教程中的下一行命令ng server就會(huì)報(bào)錯(cuò):

$ 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

初次使用,不太懂怎么處理,還請(qǐng)同學(xué)們幫幫忙,十分感謝。

回答
編輯回答
愚念

歡迎加入開(kāi)源社區(qū)!在這個(gè)社區(qū)里,就是會(huì)出現(xiàn)各種不匹配,有的時(shí)候需要等大佬們發(fā)新版來(lái)互相匹配,有的時(shí)候耐不性子,親自上場(chǎng)打怪,開(kāi)pull request幫大佬們除妖也是一個(gè)辦法。

你這個(gè)問(wèn)題導(dǎo)致的原因是:Angular版本太超前了,而ng-alain版本還沒(méi)有跟上導(dǎo)致的。注意看錯(cuò)誤信息:

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

ng-alian說(shuō)它需要@angular-devkit/core@^0.6.1,而你提供的版本是:

@angular-devkit/core              0.8.1

所以目前有3個(gè)辦法:

  1. 坐等ng-alain發(fā)新版支持0.8.1。4個(gè)小時(shí)前ng-alain剛剛發(fā)表1.4.2版本,查看它的package.json文件,你會(huì)發(fā)現(xiàn),他們剛剛開(kāi)始支持0.8.0。而它支持的Angular版本僅僅只是6.1.0,而你安裝的Angular版本是6.1.7,所以目前還是匹配不上?;蛘吣阋部梢园阉麄兊脑创a下載下來(lái),改造成支持Angular 6.1.7的再上傳上去,看他們是否愿意接受。
  2. 改造自己的package.json文件,把里面所有寫(xiě)著6.1.7的地方,改成6.1.0或者更低,然后重新npm install。
  3. 不手動(dòng)修改package.json,而是重新安裝低版本的angular cli,然后重新生成項(xiàng)目:
npm uninstall -g angular-cli
npm cache clean
npm install -g angular-cli@6.1.0
2017年12月18日 16:30