npm update --save 产生错误并阻止 ng serve 的 运行
npm update --save producing error and block the run of ng serve
我是 运行 npm update --save
之后 运行 我的 angular cli 项目它产生以下错误
ERROR in AppModule is not an NgModule
ERROR in ./src/main.ts
Module build failed: TypeError: Cannot read property 'newLine' of undefined
at Object.getNewLineCharacter (/home/nifras/Documents/web-cli/node_modules/typescript/lib/typescript.js:9514:20)
at Object.createCompilerHost (/home/nifras/Documents/web-cli/node_modules/typescript/lib/typescript.js:63770:26)
at Object.ngcLoader (/home/nifras/Documents/web-cli/node_modules/@ngtools/webpack/src/loader.js:329:31)
@ multi webpack-dev-server/client?http://localhost:4200 ./src/main.ts
我无法找出错误。在我的假设中,错误是产生了未满足的打字稿版本。如何修复此错误
我在下面添加了 package.json 和 angular-cli.json
package.json
{
"name": "coral-web",
"version": "0.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.4.10",
"@angular/compiler": "^2.4.10",
"@angular/compiler-cli": "2.4.10",
"@angular/core": "^2.4.10",
"@angular/forms": "^2.4.10",
"@angular/http": "^2.4.10",
"@angular/platform-browser": "^2.4.10",
"@angular/platform-browser-dynamic": "^2.4.10",
"@angular/router": "^3.4.10",
"@ng-idle/core": "^2.0.0-beta.8",
"@ng-idle/keepalive": "^2.0.0-beta.8",
"@ngrx/core": "^1.2.0",
"@ngrx/store": "^2.2.1",
"@types/node": "^6.0.65",
"angular2-moment": "^1.3.1",
"bootstrap-material-design": "^0.5.10",
"codelyzer": "^2.0.1",
"core-js": "^2.4.1",
"gentelella": "^1.3.0",
"ng2-loading-bar": "0.0.6",
"ng2-slim-loading-bar": "^2.4.0",
"primeng": "^4.0.0-rc.1",
"rxjs": "^5.1.1",
"ts-helpers": "^1.1.1",
"tslint": "^4.5.1",
"typescript": "^2.2.1",
"zone.js": "^0.8.4"
},
"devDependencies": {
"@angular/cli": "1.0.0-rc.2",
"@angular/compiler-cli": "^2.3.1",
"@types/jasmine": "2.5.46",
"@types/node": "^7.0.8",
"codelyzer": "~3.0.0-beta.3",
"jasmine-core": "2.5.2",
"jasmine-spec-reporter": "3.2.0",
"karma": "1.5.0",
"karma-chrome-launcher": "^2.0.0",
"karma-cli": "^1.0.1",
"karma-jasmine": "^1.0.2",
"karma-remap-istanbul": "^0.6.0",
"protractor": "~5.1.1",
"ts-node": "2.1.0",
"tslint": "^4.3.0",
"typescript": "~2.2.1",
"webdriver-manager": "12.0.4"
}
}
angualr-cli.json
{
"project": {
"version": "1.0.0-beta.21",
"name": "coral-web"
},
"apps": [
{
"root": "src",
"outDir": "dist",
"assets": [
"assets",
"favicon.ico"
],
"index": "index.html",
"main": "main.ts",
"test": "test.ts",
"tsconfig": "tsconfig.json",
"prefix": "app",
"mobile": false,
"styles": [
"styles.css",
"../node_modules/gentelella/vendors/iCheck/skins/flat/green.css",
"../node_modules/gentelella/vendors/font-awesome/css/font-awesome.min.css",
"../node_modules/primeng/resources/themes/omega/theme.css",
"../node_modules/primeng/resources/primeng.min.css"
],
"scripts": [
"../node_modules/gentelella/vendors/jquery/dist/jquery.min.js",
"../node_modules/gentelella/vendors/bootstrap/dist/js/bootstrap.min.js",
"../node_modules/gentelella/vendors/moment/min/moment.min.js",
"../node_modules/gentelella/vendors/bootstrap-daterangepicker/daterangepicker.js",
"../node_modules/gentelella/vendors/fastclick/lib/fastclick.js",
"../node_modules/gentelella/vendors/nprogress/nprogress.js",
"../node_modules/gentelella/vendors/Chart.js/dist/Chart.min.js",
"../node_modules/gentelella/vendors/gauge.js/dist/gauge.min.js",
"../node_modules/gentelella/vendors/bootstrap-progressbar/bootstrap-progressbar.min.js",
"../node_modules/gentelella/vendors/iCheck/icheck.min.js",
"../node_modules/gentelella/vendors/skycons/skycons.js",
"../node_modules/gentelella/build/js/custom.min.js"
],
"environmentSource": "environments/environment.ts",
"environments": {
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts"
}
}
],
"addons": [],
"packages": [],
"e2e": {
"protractor": {
"config": "./protractor.conf.js"
}
},
"test": {
"karma": {
"config": "./karma.conf.js"
}
},
"defaults": {
"styleExt": "css",
"prefixInterfaces": false,
"inline": {
"style": false,
"template": false
},
"spec": {
"class": false,
"component": true,
"directive": true,
"module": false,
"pipe": true,
"service": true
}
}
}
有点晚了,但也许其他人会再次遇到这个问题。
关于您的 angular-cli.json 您来自低于 beta.28 的 cli beta 版本,因此仅 npm update 是不够的。
按照说明更新 angualr cli
official wiki.
If you're using Angular CLI beta.28 or less, you need to uninstall the
angular-cli package.
npm uninstall -g angular-cli
npm uninstall --save-dev angular-cli
To update Angular CLI to a new version, you must update both the global
package and your project's local package.
Global package:
npm uninstall -g @angular/cli
npm cache clean
npm install -g @angular/cli@latest
Local project package:
rm -rf node_modules dist # use rmdir on Windows
npm install --save-dev @angular/cli@latest
npm install
我是 运行 npm update --save
之后 运行 我的 angular cli 项目它产生以下错误
ERROR in AppModule is not an NgModule
ERROR in ./src/main.ts
Module build failed: TypeError: Cannot read property 'newLine' of undefined
at Object.getNewLineCharacter (/home/nifras/Documents/web-cli/node_modules/typescript/lib/typescript.js:9514:20)
at Object.createCompilerHost (/home/nifras/Documents/web-cli/node_modules/typescript/lib/typescript.js:63770:26)
at Object.ngcLoader (/home/nifras/Documents/web-cli/node_modules/@ngtools/webpack/src/loader.js:329:31)
@ multi webpack-dev-server/client?http://localhost:4200 ./src/main.ts
我无法找出错误。在我的假设中,错误是产生了未满足的打字稿版本。如何修复此错误
我在下面添加了 package.json 和 angular-cli.json
package.json
{
"name": "coral-web",
"version": "0.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.4.10",
"@angular/compiler": "^2.4.10",
"@angular/compiler-cli": "2.4.10",
"@angular/core": "^2.4.10",
"@angular/forms": "^2.4.10",
"@angular/http": "^2.4.10",
"@angular/platform-browser": "^2.4.10",
"@angular/platform-browser-dynamic": "^2.4.10",
"@angular/router": "^3.4.10",
"@ng-idle/core": "^2.0.0-beta.8",
"@ng-idle/keepalive": "^2.0.0-beta.8",
"@ngrx/core": "^1.2.0",
"@ngrx/store": "^2.2.1",
"@types/node": "^6.0.65",
"angular2-moment": "^1.3.1",
"bootstrap-material-design": "^0.5.10",
"codelyzer": "^2.0.1",
"core-js": "^2.4.1",
"gentelella": "^1.3.0",
"ng2-loading-bar": "0.0.6",
"ng2-slim-loading-bar": "^2.4.0",
"primeng": "^4.0.0-rc.1",
"rxjs": "^5.1.1",
"ts-helpers": "^1.1.1",
"tslint": "^4.5.1",
"typescript": "^2.2.1",
"zone.js": "^0.8.4"
},
"devDependencies": {
"@angular/cli": "1.0.0-rc.2",
"@angular/compiler-cli": "^2.3.1",
"@types/jasmine": "2.5.46",
"@types/node": "^7.0.8",
"codelyzer": "~3.0.0-beta.3",
"jasmine-core": "2.5.2",
"jasmine-spec-reporter": "3.2.0",
"karma": "1.5.0",
"karma-chrome-launcher": "^2.0.0",
"karma-cli": "^1.0.1",
"karma-jasmine": "^1.0.2",
"karma-remap-istanbul": "^0.6.0",
"protractor": "~5.1.1",
"ts-node": "2.1.0",
"tslint": "^4.3.0",
"typescript": "~2.2.1",
"webdriver-manager": "12.0.4"
}
}
angualr-cli.json
{
"project": {
"version": "1.0.0-beta.21",
"name": "coral-web"
},
"apps": [
{
"root": "src",
"outDir": "dist",
"assets": [
"assets",
"favicon.ico"
],
"index": "index.html",
"main": "main.ts",
"test": "test.ts",
"tsconfig": "tsconfig.json",
"prefix": "app",
"mobile": false,
"styles": [
"styles.css",
"../node_modules/gentelella/vendors/iCheck/skins/flat/green.css",
"../node_modules/gentelella/vendors/font-awesome/css/font-awesome.min.css",
"../node_modules/primeng/resources/themes/omega/theme.css",
"../node_modules/primeng/resources/primeng.min.css"
],
"scripts": [
"../node_modules/gentelella/vendors/jquery/dist/jquery.min.js",
"../node_modules/gentelella/vendors/bootstrap/dist/js/bootstrap.min.js",
"../node_modules/gentelella/vendors/moment/min/moment.min.js",
"../node_modules/gentelella/vendors/bootstrap-daterangepicker/daterangepicker.js",
"../node_modules/gentelella/vendors/fastclick/lib/fastclick.js",
"../node_modules/gentelella/vendors/nprogress/nprogress.js",
"../node_modules/gentelella/vendors/Chart.js/dist/Chart.min.js",
"../node_modules/gentelella/vendors/gauge.js/dist/gauge.min.js",
"../node_modules/gentelella/vendors/bootstrap-progressbar/bootstrap-progressbar.min.js",
"../node_modules/gentelella/vendors/iCheck/icheck.min.js",
"../node_modules/gentelella/vendors/skycons/skycons.js",
"../node_modules/gentelella/build/js/custom.min.js"
],
"environmentSource": "environments/environment.ts",
"environments": {
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts"
}
}
],
"addons": [],
"packages": [],
"e2e": {
"protractor": {
"config": "./protractor.conf.js"
}
},
"test": {
"karma": {
"config": "./karma.conf.js"
}
},
"defaults": {
"styleExt": "css",
"prefixInterfaces": false,
"inline": {
"style": false,
"template": false
},
"spec": {
"class": false,
"component": true,
"directive": true,
"module": false,
"pipe": true,
"service": true
}
}
}
有点晚了,但也许其他人会再次遇到这个问题。
关于您的 angular-cli.json 您来自低于 beta.28 的 cli beta 版本,因此仅 npm update 是不够的。
按照说明更新 angualr cli official wiki.
If you're using Angular CLI beta.28 or less, you need to uninstall the angular-cli package.
npm uninstall -g angular-cli
npm uninstall --save-dev angular-cli
To update Angular CLI to a new version, you must update both the global package and your project's local package.
Global package:
npm uninstall -g @angular/cli npm cache clean npm install -g @angular/cli@latest
Local project package:
rm -rf node_modules dist # use rmdir on Windows npm install --save-dev @angular/cli@latest npm install