升级angular cli后无法使用“ng serve”为我的应用程序提供服务

时间:2017-05-14 11:42:58

标签: angular angular-cli

我有一个Angular 2应用程序运行正常,但在升级angular cli后,我无法使用ng serve提供我的应用程序。

我有以下错误:

ng serve                                  
Version of @angular/compiler-cli needs to be 2.3.1 or greater. Current version is "undefined".
Error: Version of @angular/compiler-cli needs to be 2.3.1 or greater. Current version is "undefined".
    at Object.<anonymous> (/home/luisjose/Documentos/TusDividendos/web/tus-dividendos2/node_modules/@ngtools/webpack/src/index.js:27:11)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.require (module.js:498:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/home/luisjose/Documentos/TusDividendos/web/tus-dividendos2/node_modules/@angular/cli/tasks/eject.js:10:19)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.require (module.js:498:17)
    at require (internal/module.js:20:19)

我按照Angular CLI migration guide中所示的所有步骤操作,这是:

sudo npm uninstall -g angular-cli
npm uninstall --save-dev angular-cli
sudo npm uninstall -g @angular/cli
npm cache clean
sudo npm install -g @angular/cli@latest
rm -rf node_modules dist
npm install --save-dev @angular/cli@latest
npm install

但是,正如我所说,我无法使用ng serve提供我的申请。

(编辑)的

我不知道我可以在ng serve的项目中运行./node_modules/.bin/ng serve。谢谢Yakov。无论如何,我全局卸载了角度cli以避免冲突。

我仍然不能为我的项目服务,但我觉得我接近解决方案; - )

我得到的错误与我在开头时发布的错误相同:

./node_modules/.bin/ng serve       
Version of @angular/compiler-cli needs to be 2.3.1 or greater. Current version is "undefined".
Error: Version of @angular/compiler-cli needs to be 2.3.1 or greater. Current version is "undefined".
    at Object.<anonymous>
...

我的package.json是这样的:

{
  "name": "tusdividendos",
  "version": "2.0.0",
  "license": "MIT",
  "angular-cli": {},
  "scripts": {
    "start": "ng serve",
    "lint": "tslint \"src/**/*.ts\"",
    "test": "ng test",
    "pree2e": "webdriver-manager update",
    "e2e": "protractor"
  },
  "private": true,
  "dependencies": {
    "@angular/common": "2.2.3",
    "@angular/compiler": "2.2.3",
    "@angular/core": "2.2.3",
    "@angular/forms": "2.2.3",
    "@angular/http": "2.2.3",
    "@angular/platform-browser": "2.2.3",
    "@angular/platform-browser-dynamic": "2.2.3",
    "@angular/router": "3.2.3",
    "angular2-materialize": "^6.3.0",
    "angularfire2": "^2.0.0-beta.6",
    "core-js": "^2.4.1",
    "firebase": "^3.6.3",
    "font-awesome": "^4.7.0",
    "jquery": "^3.1.1",
    "materialize-css": "^0.97.8",
    "rxjs": "5.0.0-beta.12",
    "ts-helpers": "^1.1.1",
    "zone.js": "^0.6.23"
  },
  "devDependencies": {
    "@angular/compiler-cli": "2.2.3",
    "@types/jasmine": "2.5.38",
    "@types/jquery": "^2.0.40",
    "@types/node": "^6.0.42",
    "angular-cli": "1.0.0-beta.22-1",
    "codelyzer": "~2.0.0-beta.1",
    "jasmine-core": "2.5.2",
    "jasmine-spec-reporter": "2.5.0",
    "karma": "1.2.0",
    "karma-chrome-launcher": "^2.0.0",
    "karma-cli": "^1.0.1",
    "karma-jasmine": "^1.0.2",
    "karma-remap-istanbul": "^0.2.1",
    "protractor": "4.0.9",
    "ts-node": "^1.7.0",
    "tslint": "^4.0.2",
    "typescript": "~2.0.3",
    "webdriver-manager": "10.2.5"
  }
}

¿任何线索?

1 个答案:

答案 0 :(得分:1)

错误消息告诉您&#34; @ angular / compiler-cli的版本需要为2.3.1或更高。&#34;看来package.json中的依赖项版本已经过时了。 生成一个新项目并查看package.json中的依赖项,并根据需要更新您的项目。例如,这就是我在新生成的项目中所拥有的:

#include<iostream>
#include<vector>
using namespace std;
class Test{
public:
        static void func(){
                cout<<"Test::func()"<<endl;
        }
};

int main(){
        vector<void(*)()>list_of_methods;
        list_of_methods.push_back(Test::func);
        list_of_methods[0]();
        return 0;
}