最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Module build failed: TypeError: Cannot read property 'newLine' of undefined - Stack Overflow

programmeradmin3浏览0评论

Everything was running fine yesterday, now when I try to ng serve I get these errors:

ERROR in ./src/main.ts Module build failed: TypeError: Cannot read property 'newLine' of undefined at Object.getNewLineCharacter (/Users/leongaban/Projects/TickerTags/wikitags/node_modules/typescript/lib/typescript.js:8062:20)

I tried the answers here and here but no effect :(

My global and local npm version for angular-cli is 1.0.0-beta.28.3 how do I upgrade that to .30? I tried @latest


My local package.json:

"devDependencies": {
    "@angular/cli": "1.0.0-beta.28.3",
    "@angular/piler-cli": "^2.4.0",

My global package:


I see that the latest is beta.32

However when I run npm install -g angular-cli@latest it still installs .28.3

Everything was running fine yesterday, now when I try to ng serve I get these errors:

ERROR in ./src/main.ts Module build failed: TypeError: Cannot read property 'newLine' of undefined at Object.getNewLineCharacter (/Users/leongaban/Projects/TickerTags/wikitags/node_modules/typescript/lib/typescript.js:8062:20)

I tried the answers here and here but no effect :(

My global and local npm version for angular-cli is 1.0.0-beta.28.3 how do I upgrade that to .30? I tried @latest


My local package.json:

"devDependencies": {
    "@angular/cli": "1.0.0-beta.28.3",
    "@angular/piler-cli": "^2.4.0",

My global package:


I see that the latest is beta.32 https://github./angular/angular-cli/releases

However when I run npm install -g angular-cli@latest it still installs .28.3

Share Improve this question edited May 23, 2017 at 12:09 CommunityBot 11 silver badge asked Feb 23, 2017 at 15:32 Leon GabanLeon Gaban 39k122 gold badges348 silver badges550 bronze badges 2
  • Strangely I could fix this by deleting the node_modules folder and then reinstall everything. – sandrooco Commented Feb 27, 2017 at 10:50
  • Does ng -v return the same package for local and global? – sandrooco Commented Feb 27, 2017 at 10:51
Add a ment  | 

7 Answers 7

Reset to default 2

In package.json I changed:

"devDependencies": {
   "@angular/cli": "1.0.0"

To:

"devDependencies": {
   "@angular/cli": "1.2.0"

OS : Windows with Angular 4

"@angular/cli": "1.2.1"

"@angular/material": "2.0.0-beta.6"

I just removed the caret from above two dependencies and performed following steps, everything started working perfectly.

  1. Remove node_module
  2. Uninstall angular cli from local and global
  3. Install the same version of angular cli in both
  4. Do "npm install"
  5. "ng serve"

They've moved to @angular/cli package name, to ply with the other @angular modules. To be sure you are not left with old files, perform the following steps:

npm uninstall -g @angular/cli
npm cache clean
npm install -g @angular/cli@latest

then remove your local node_modules folder and execute:

npm install --save-dev @angular/cli@latest
npm install

The latest angular cli version is .32. There are still issues with upgrading to newer versions, but hopefully with the next update they will have that under control. If not, repeat the steps I just mentioned

What worked for me is:

diff --git a/angular-cli.json b/angular-cli.json
index d74d5d4..2641672 100644
--- a/angular-cli.json
+++ b/angular-cli.json
@@ -1,7 +1,7 @@
 {
   "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
   "project": {
-    "version": "1.0.0-beta.31",
+    "version": "1.0.0-beta.28",
     "name": "renaissance"
   },
   "apps": [
@@ -22,8 +22,8 @@
         "styles.less"
       ],
       "scripts": [],
+      "environmentSource": "environments/environment.ts",
       "environments": {
-        "source": "environments/environment.ts",
         "dev": "environments/environment.ts",
         "prod": "environments/environment.prod.ts"
       }
diff --git a/package.json b/package.json
index b91db8f..7e2b083 100644
--- a/package.json
+++ b/package.json
@@ -12,13 +12,13 @@
   },
   "private": true,
   "dependencies": {
-    "@angular/mon": "^2.4.0",
-    "@angular/piler": "^2.4.0",
-    "@angular/core": "^2.4.0",
-    "@angular/forms": "^2.4.0",
-    "@angular/http": "^2.4.0",
-    "@angular/platform-browser": "^2.4.0",
-    "@angular/platform-browser-dynamic": "^2.4.0",
+    "@angular/mon": "^2.4.8",
+    "@angular/piler": "^2.4.8",
+    "@angular/core": "^2.4.8",
+    "@angular/forms": "^2.4.8",
+    "@angular/http": "^2.4.8",
+    "@angular/platform-browser": "^2.4.8",
+    "@angular/platform-browser-dynamic": "^2.4.8",
     "@angular/router": "^3.4.0",
     "@ng-bootstrap/ng-bootstrap": "^1.0.0-alpha.20",
     "angularfire2": "^2.0.0-beta.8",
@@ -27,15 +27,14 @@
     "font-awesome": "^4.7.0",
     "moment": "^2.17.1",
     "ng2-bootstrap": "^1.3.3",
-    "ng2-page-transition": "^0.2.6",
+    "ng2-page-transition": "^1.0.4",
     "rxjs": "^5.0.1",
     "ts-helpers": "^1.1.1",
     "web-animations-js": "^2.2.2",
     "zone.js": "^0.7.2"
   },
   "devDependencies": {
-    "@angular/cli": "1.0.0-beta.31",
-    "@angular/piler-cli": "^2.4.0",
+    "@angular/cli": "^1.0.0-beta.32.3",
     "@types/jasmine": "2.5.38",
     "@types/node": "^6.0.42",
     "codelyzer": "~2.0.0-beta.1",
@@ -44,8 +43,8 @@
     "karma": "1.2.0",
     "karma-chrome-launcher": "^2.0.0",
     "karma-cli": "^1.0.1",
-    "karma-jasmine": "^1.0.2",
     "karma-coverage-istanbul-reporter": "^0.2.0",
+    "karma-jasmine": "^1.0.2",
     "protractor": "~5.1.0",
     "ts-node": "1.2.1",
     "tslint": "^4.3.0",
diff --git a/src/app/app.module.ts b/src/app/app.module.ts
index 1f862c6..b6568b7 100644
--- a/src/app/app.module.ts
+++ b/src/app/app.module.ts
@@ -8,7 +8,7 @@ import {NgbModule} from '@ng-bootstrap/ng-bootstrap';
 // App modules/ponents
 import {LayoutsModule} from "./Components/mon/layout/layout.module";
 import {BlochWidgetsModule} from "./Components/mon/widgets/widgets.module";
-import {Ng2PageTransition} from "ng2-page-transition";
+import {Ng2PageTransitionModule} from "ng2-page-transition";
 //services
 import {PeopleHttpService} from "./Components/mon/service/httpPeople.service";
 //auth Module
@@ -30,9 +30,9 @@ import {MessagingModule} from "./views/messaging/messaging.module";
 @NgModule({
   declarations: [
     AppComponent,
-    Ng2PageTransition,
   ],
   imports: [
+    Ng2PageTransitionModule,
     BrowserModule,
     FormsModule,
     HttpModule,

This worked for me :-
rm -rf node_modules && npm cache clean && npm uninstall --save angular-cli; npm uninstall -g angular-cli; npm i --save @angular/cli && npm i -g @angular/cli && npm i

rm -rf node_modules/ in your project to get rid of all npm stuff and then npm cache clean followed by npm install should also resolve this issue. Also, make sure the versions of the cli locally and globally match.

https://github./angular/angular-cli/issues/3781

So none of the install @angular/cli@latest worked for me, most likely will work in the future I presume.

I had another angular2 project which was ng serve-ing fine. So I just copied the package.json dependencies from it and updated the angular-cli.json.

And now it works again!

package.json

"dependencies": {
    "@angular/mon": "^2.4.0",
    "@angular/piler": "^2.4.0",
    "@angular/core": "^2.4.0",
    "@angular/forms": "^2.4.0",
    "@angular/http": "^2.4.0",
    "@angular/platform-browser": "^2.4.0",
    "@angular/platform-browser-dynamic": "^2.4.0",
    "@angular/router": "^3.4.0",
    "core-js": "^2.4.1",
    "rxjs": "^5.0.1",
    "ts-helpers": "^1.1.1",
    "zone.js": "^0.7.2"
  },
  "devDependencies": {
    "@angular/cli": "1.0.0-beta.31",
    "@angular/piler-cli": "^2.4.0",
    "@types/jasmine": "2.5.38",
    "@types/node": "^6.0.42",
    "codelyzer": "~2.0.0-beta.1",
    "css-loader": "^0.26.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-coverage-istanbul-reporter": "^0.2.0",
    "karma-jasmine": "^1.0.2",
    "node-sass": "^4.5.0",
    "node-sass-import": "^1.1.1",
    "protractor": "~5.1.0",
    "sass-loader": "^6.0.0",
    "source-map-loader": "^0.1.6",
    "ts-node": "1.2.1",
    "tslint": "^4.3.0",
    "typescript": "~2.0.0"
  }

angular-cli.json

Had to revert back to the older type of "source" key

"environments": {
    "source": "environments/environment.ts",
    "dev": "environments/environment.ts",
    "prod": "environments/environment.prod.ts"
}

Just update to "@angular/cli": "1.0.0-rc.0" "@angular/piler-cli": "2.4.0" in your package.json and update file angular-cli.json like below

change

"environments": {
    "source": "environments/environment.ts",
    "dev": "environments/environment.ts",
    "prod": "environments/environment.prod.ts"
}

by

"environmentSource": "environments/environment.ts",
      "environments": {
        "dev": "environments/environment.ts",
        "prod": "environments/environment.prod.ts"
      }  
发布评论

评论列表(0)

  1. 暂无评论