Module build failed: TypeError: Cannot read property 'newLine' of undefined

前端 未结 7 828
春和景丽
春和景丽 2021-01-17 16:26

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

相关标签:
7条回答
  • 2021-01-17 16:49

    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/common": "^2.4.0",
    -    "@angular/compiler": "^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/common": "^2.4.8",
    +    "@angular/compiler": "^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/compiler-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/components
     import {LayoutsModule} from "./Components/common/layout/layout.module";
     import {BlochWidgetsModule} from "./Components/common/widgets/widgets.module";
    -import {Ng2PageTransition} from "ng2-page-transition";
    +import {Ng2PageTransitionModule} from "ng2-page-transition";
     //services
     import {PeopleHttpService} from "./Components/common/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,
    
    0 讨论(0)
  • 2021-01-17 16:55

    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/common": "^2.4.0",
        "@angular/compiler": "^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/compiler-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"
    }
    
    0 讨论(0)
  • 2021-01-17 16:58

    Just update to "@angular/cli": "1.0.0-rc.0" "@angular/compiler-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 讨论(0)
  • 2021-01-17 17:03

    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.com/angular/angular-cli/issues/3781

    0 讨论(0)
  • 2021-01-17 17:05

    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"
    0 讨论(0)
  • 2021-01-17 17:09

    They've moved to @angular/cli package name, to comply 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

    0 讨论(0)
提交回复
热议问题