最近接手一個Angular項目的維護,包依賴以下:javascript
// package.json
···
"dependencies": {
"@angular/animations": "4.1.3",
"@angular/common": "4.1.0",
"@angular/compiler": "4.1.0",
"@angular/core": "4.1.0",
"@angular/forms": "4.1.0",
"@angular/http": "4.1.0",
"@angular/platform-browser": "4.1.0",
"@angular/platform-browser-dynamic": "4.1.0",
"@angular/platform-server": "4.1.0",
"@angular/router": "4.1.0",
"@ng-bootstrap/ng-bootstrap": "1.0.0-alpha.25",
"@ngx-translate/core": "6.0.1",
"@ngx-translate/http-loader": "0.0.3",
"@ntesmail/shark-angular2": "^1.2.2",
"aircraftcarrier-ngx-charts": "^6.0.5",
"aircraftcarrier-oauth-access-token": "^1.1.6",
"amcharts3": "^3.21.0",
"ammap3": "^3.21.14",
"angular2-cookie": "^1.2.6",
"angular2-datatable": "0.6.0",
"animate.css": "3.5.2",
"body-parser": "~1.13.2",
"bootstrap": "4.0.0-alpha.6",
"chart.js": "1.1.1",
"chartist": "0.10.1",
"chroma-js": "1.3.3",
"ckeditor": "4.6.2",
"cookie-parser": "~1.3.5",
"core-js": "2.4.1",
"cross-env": "^3.2.4",
"d3": "^4.12.2",
"easy-pie-chart": "2.1.7",
"egg": "^1.2.0",
"egg-cookies": "^2.2.1",
"egg-cors": "^1.1.0",
"egg-development-proxyagent": "^1.0.0",
"egg-dubbo": "^1.0.1",
"egg-mongo-native": "^1.0.6",
"egg-mongoose": "^2.1.0",
"egg-multipart": "^1.3.0",
"egg-oss": "^1.0.2",
"egg-redis": "^1.0.2",
"egg-scripts": "^2.11.0",
"egg-static": "^1.3.0",
"egg-view-nunjucks": "^2.0.0",
"excel-export": "^0.5.1",
"font-awesome": "4.7.0",
"formstream": "^1.1.0",
"fullcalendar": "3.3.1",
"google-maps": "3.2.1",
"html-pdf": "^2.2.0",
"intl": "^1.2.5",
"ionicons": "2.0.1",
"jquery": "3.2.1",
"jquery-slimscroll": "1.3.8",
"leaflet": "0.7.7",
"leaflet-map": "0.2.1",
"lodash": "4.17.4",
"md5": "^2.2.1",
"moment": "^2.18.1",
"morgan": "~1.6.1",
"ng2-ckeditor": "1.1.6",
"ng2-completer": "1.3.1",
"ng2-handsontable": "0.48.0",
"ng2-interceptors": "^1.3.0-1",
"ng2-slim-loading-bar": "4.0.0",
"ng2-smart-table": "1.0.3",
"ng2-tree": "2.0.0-alpha.5",
"ngx-uploader": "2.2.5",
"node-xlsx": "^0.10.0",
"normalize.css": "6.0.0",
"roboto-fontface": "0.7.0",
"rxjs": "5.1.1",
"serve-favicon": "~2.3.0",
"stream-wormhole": "^1.0.3",
"zone.js": "0.8.5"
},
"devDependencies": {
"@angular/cli": "1.0.1",
"@angular/compiler-cli": "4.1.0",
"@types/fullcalendar": "2.7.40",
"@types/jasmine": "2.5.38",
"@types/jquery": "2.0.41",
"@types/jquery.slimscroll": "1.3.30",
"@types/lodash": "4.14.61",
"@types/node": "6.0.69",
"amcharts3": "^3.21.0",
"autod": "^2.7.1",
"browser-sync": "latest",
"cheerio": "^0.22.0",
"codelyzer": "2.0.0",
"consolidate": "^0.14.5",
"cross-env": "^3.2.4",
"egg-bin": "^3.2.0",
"egg-mock": "^3.2.0",
"eslint": "^3.13.1",
"eslint-config-egg": "^3.2.0",
"express": "^4.15.2",
"gh-pages": "0.12.0",
"glob": "^7.0.0",
"jasmine-core": "2.5.2",
"jasmine-spec-reporter": "3.2.0",
"karma": "1.4.1",
"karma-chrome-launcher": "2.0.0",
"karma-cli": "1.0.1",
"karma-coverage-istanbul-reporter": "0.2.0",
"karma-jasmine": "1.1.0",
"karma-jasmine-html-reporter": "0.2.2",
"lodash": "^4.17.4",
"ncp": "^2.0.0",
"ng2-completer": "^1.2.2",
"npm-run-all": "4.0.2",
"protractor": "5.1.0",
"reload": "^1.1.1",
"rimraf": "2.6.1",
"standard-changelog": "1.0.1",
"stylelint": "7.10.1",
"supertest": "^2.0.1",
"supervisor": "^0.12.0",
"ts-node": "2.0.0",
"tslint": "4.5.0",
"tslint-eslint-rules": "3.5.1",
"tslint-language-service": "0.9.2",
"typescript": "2.2.2",
"typogr": "0.6.6",
"underscore": "1.8.3",
"webstorm-disable-index": "^1.2.0",
"wintersmith": "2.2.5",
"wintersmith-sassy": "1.2.0"
},
"scripts": {
"ng": "ng",
"rimraf": "rimraf",
"changelog": "standard-changelog",
"start": "cross-env EGG_SERVER_ENV=prod NODE_ENV=prod node dispatch.js",
"dev": "cross-env EGG_SERVER_ENV=test NODE_ENV=prod node dispatch.js",
"client": "ng serve --proxy-conf build/proxy.conf.json --host localhost --port 8088",
"serve": "cd app && eslint . && cd .. && cross-env NODE_ENV=local http_proxy=http://127.0.0.1:8888 egg-bin dev",
"start:hmr": "ng serve --hmr",
"start:aot": "ng serve --aot",
"start:prod": "ng serve --prod",
"start:prod:aot": "ng serve --prod --aot",
"build": "npm run clean:dist && ng build --output-path app/goodsCarriers",
"build:prod": "npm run build -- --prod",
"build:prod:aot": "npm run build:prod -- --aot",
"build:ci": "npm run build:prod && npm run build:prod:aot",
"test": "ng test -sr",
"test:coverage": "npm run clean:coverage && ng test -sr -cc",
"lint": "ng lint",
"lint:styles": "stylelint ./src/app/**/*.scss",
"lint:ci": "npm run lint && npm run lint:styles",
"pree2e": "webdriver-manager update --standalone false --gecko false",
"e2e": "ng e2e",
"clean:dist": "npm run rimraf -- app/goodsCarriers",
"clean:coverage": "npm run rimraf -- coverage",
"docs:deploy": "wintersmith build -C docs && gh-pages -d docs/build",
"docs:serve": "wintersmith preview -C docs"
}
···
複製代碼
^
跟~
的區別是啥?
^
大版本;~
小版本。保留這些符號即不鎖定依賴包的版本號,不然鎖定。所有去掉最保險,但內部包不要去掉。css
README.md
文件說明運行npm install
安裝項目依賴。npm run client
命令啓動客戶端服務。報錯如圖:
一般,檢測項目環境如何都會運行相關命令查看版本號,若是有正常輸出,說明環境存在;不然環境待安裝。如: html
同理,「'ng'不是內部或外部命令,也不是可運行的程序或批處理文件。」初步猜想是Angular環境未安裝。運行ng v
,如圖: java
如此,那運行npm install -g @angular/cli
安裝下Angular CLI吧~如圖: node
再次運行npm run client
命令嘗試啓動客戶端服務。報錯如圖: jquery
回頭看package.json
文件中依賴包的版本設置,初步猜想是版本號不匹配報錯。那咱嚴格按照package.json
文件中指定的依賴版原本安裝吧!web
npm uninstall -g @angualr/cliredis
npm cache verifychrome
common not found
即卸載乾淨
ng vtypescript
npm install -g @angular/cli@1.0.1
一通折騰後,運行ng v
,輸出如圖:
可見,好些@angular/
包都未成功安裝,再次運行npm run client
嘗試啓動項目,仍舊報錯,如圖:
鬱悶!npm install
不是安裝全部package.json
文件中所列的依賴嗎?怎麼啓動項目的時候仍是有依賴未安裝的提示呢?極有是該項目的版本太舊了...可是當下也沒太多精力對其升級,怎麼辦?
npm install
未成功安裝的依賴。分析目前的信息提示,大可能是dependencies
中的依賴缺失,那單獨再統一安裝一次呢?
運行npm install --dependencies
完成後,再次運行npm run client
,終於再也不報錯了,如圖:
啊!啊!啊!安全綠~成功人士頭頂都須要那麼點綠,看來是真的~哈哈哈,將來可期!將來可期...
至此,項目維護第一步 —— 項目啓動已解決,繼續搬磚ING~
這次問題關鍵是@angular/cli@1.0.1
依賴包版本鎖定致使的依賴包安裝不徹底引發的。確保相關依賴成功安裝後,沒有啓動不起來的項目。fighting~