angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

ng serve --aot fail after file change

Open WandererInVoids opened this issue 8 years ago • 67 comments

Bug Report or Feature Request (mark with an x)

- [X] bug report -> please search issues before submitting
- [ ] feature request

Command (mark with an x)

- [ ] new
- [ ] build
- [x] serve
- [ ] test
- [ ] e2e
- [ ] generate
- [ ] add
- [ ] update
- [ ] lint
- [ ] xi18n
- [ ] run
- [ ] config
- [ ] help
- [ ] version
- [ ] doc

Versions

Angular CLI: 6.1.2 Node: 10.0.0 OS: win32 x64 Angular: 6.1.2 ... animations, cli, common, compiler, compiler-cli, core, forms ... http, language-service, platform-browser ... platform-browser-dynamic, platform-server, router ... service-worker

Package Version

@angular-devkit/architect 0.7.2 @angular-devkit/build-angular 0.7.2 @angular-devkit/build-optimizer 0.7.2 @angular-devkit/build-webpack 0.7.2 @angular-devkit/core 0.7.2 @angular-devkit/schematics 0.7.2 @angular/cdk 6.4.3 @angular/material 6.4.3 @ngtools/webpack 6.1.2 @schematics/angular 0.7.2 @schematics/update 0.7.2 rxjs 6.2.2 typescript 2.9.2 webpack 4.9.2 -->

Repro steps

  1. run ng serve with aot flag
  2. change something in watch filles
  3. see error in module find(file that change)

The log given by the failure

Module not found: Error: Can't resolve '@angular/material/button.ngfactory' in 'D:\Flare\flare.ui2\src\homeapp\app\components\reports\profitAndLoss'
ERROR in ./src/homeapp/app/components/reports/profitAndLoss/profit.and.loss.ngfactory.js
Module not found: Error: Can't resolve '@angular/material/checkbox.ngfactory' in 'D:\Flare\flare.ui2\src\homeapp\app\components\reports\profitAndLoss'
ERROR in ./src/homeapp/app/components/reports/profitAndLoss/profit.and.loss.ngfactory.js
Module not found: Error: Can't resolve '@angular/material/form-field.ngfactory' in '.\src\homeapp\app\components\reports\profitAndLoss'
ERROR in ./src/homeapp/app/components/reports/profitAndLoss/profit.and.loss.ngfactory.js
Module not found: Error: Can't resolve '@angular/material/menu.ngfactory' in '.\src\homeapp\app\components\reports\profitAndLoss'

Date: 2018-08-09T17:57:03.581Z - Hash: 12b8572033feade48d1a - Time: 34472ms
4 unchanged chunks
chunk {main} main.js (main) 16.2 MB [initial] [rendered]

i 「wdm」: Failed to compile.

Desired functionality

work as before update

Mention any other details that might be useful

I didn't know where to write, in @angular/compile or here but error showed in cli, so... This breaking from this fix https://github.com/angular/angular/pull/25335. Reverting @angular/compiler to 6.1.1 workaround for this. I tested without fix, it work as before.

WandererInVoids avatar Aug 09 '18 18:08 WandererInVoids

Hmm, still no luck. Cleared out node_modules folder and re-ran npm install. Checked the installed versions of @angular/compiler and @angular/compiler-cli directly in their package.json files and confirmed both are set to 6.1.6. Also tried updating to @latest for these two deps. which updated them to 6.1.7 but the issue was still there.

Just to be clear, I can build and serve the app without issue using ng serve <appname> and ng build <appname> commands but both ng serve <appname> --aot and ng build <appname> --prod fail.

Could it make a difference that the app is a hybrid Angular/AngularJS app?

package.json file below...

{
  "name": "appname",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "prettier:write": "prettier --write \"projects/**/*.ts\""
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^6.1.6",
    "@angular/cdk": "^6.4.3",
    "@angular/common": "^6.1.6",
    "@angular/core": "^6.1.6",
    "@angular/forms": "^6.1.6",
    "@angular/http": "^6.1.6",
    "@angular/material": "^6.4.4",
    "@angular/platform-browser": "^6.1.6",
    "@angular/platform-browser-dynamic": "^6.1.6",
    "@angular/router": "^6.1.6",
    "@angular/upgrade": "^6.1.6",
    "@ngrx/effects": "^6.1.0",
    "@ngrx/entity": "^6.1.0",
    "@ngrx/router-store": "^6.1.0",
    "@ngrx/store": "^6.1.0",
    "@ngrx/store-devtools": "^6.1.0",
    "@types/angular": "^1.6.50",
    "@uirouter/angular-hybrid": "^6.0.2",
    "angular": "^1.7.3",
    "angular-file-upload": "^2.5.0",
    "angular-smart-table": "^2.1.11",
    "angular-strap": "^2.3.12",
    "angular-toastr": "^2.1.1",
    "angular-ui-grid": "^4.6.3",
    "bootstrap": "^4.1.3",
    "core-js": "^2.5.4",
    "d3": "^3.5.10",
    "font-awesome": "^4.7.0",
    "jquery": "^3.3.1",
    "papaparse": "^4.6.0",
    "ramda": "^0.25.0",
    "rx-angular": "^1.1.3",
    "rxjs": "^6.0.0",
    "ui-select": "^0.19.8",
    "zone.js": "~0.8.26"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^0.7.5",
    "@angular/cli": "^6.1.5",
    "@angular/compiler": "^6.1.6",
    "@angular/compiler-cli": "^6.1.6",
    "@angular/language-service": "6.1.6",
    "@ngrx/schematics": "^6.1.0",
    "@types/jasmine": "~2.8.6",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "~8.9.4",
    "codelyzer": "~4.2.1",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~1.7.1",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.0",
    "karma-jasmine": "~1.1.1",
    "karma-jasmine-html-reporter": "^0.2.2",
    "node-sass": "^4.9.3",
    "prettier": "^1.14.2",
    "protractor": "~5.3.0",
    "ts-node": "~5.0.1",
    "tslint": "~5.9.1",
    "typescript": "~2.9.2"
  }
}

rabbit-will-run avatar Sep 06 '18 14:09 rabbit-will-run

Just now reading through the docs on compiling hybrid apps... yea, seems like issue for me is due to missed steps in configuration for aot/hybrid app - namely that arrow functions can't be used. Thanks for the feedback all!

rabbit-will-run avatar Sep 07 '18 12:09 rabbit-will-run

This was angular core issue and fixed in @angular/core 6.1.7

nasserghiasi avatar Sep 18 '18 10:09 nasserghiasi

I am still getting the Module not found Error.

node 10.11.0 npm 6.4.1

 "@angular/common": "^6.1.8",
    "@angular/core": "^6.1.8",
    "@angular/compiler": "^6.1.8",
    "@angular/animations": "^6.1.8",
    "@angular/forms": "^6.1.8",
    "@angular/http": "^6.1.8",
    "@angular/platform-browser": "^6.1.8",
    "@angular/platform-browser-dynamic": "^6.1.8",
    "@angular/router": "^6.1.8",

    "@angular/cli": "~6.2.3",
    "@angular/compiler-cli": "^6.1.8",
    "@angular/language-service": "^6.1.8",

Andrii-A avatar Sep 21 '18 15:09 Andrii-A

I also still have problems with angular 6.1.9

"@angular/animations": "6.1.9", "@angular/cdk": "^6.4.2", "@angular/common": "6.1.9", "@angular/compiler": "6.1.9", "@angular/core": "6.1.9", "@angular/flex-layout": "^6.0.0-beta.17", "@angular/forms": "6.1.9", "@angular/http": "6.1.9", "@angular/material": "^6.4.2", "@angular/material-moment-adapter": "^6.4.2", "@angular/platform-browser": "6.1.9", "@angular/platform-browser-dynamic": "6.1.9", "@angular/router": "6.1.9", "ajv": "^6.5.2", "angular-in-memory-web-api": "^0.6.0", "bootstrap": "^4.1.0", "core-js": "^2.5.5", "d3-ng2-service": "^2.2.0", "hammerjs": "^2.0.8", "jquery": "^3.3.1", "lodash": "^4.17.5", "moment": "^2.22.2", "node-sass": "^4.9.2", "popper.js": "^1.14.3", "pump": "^2.0.1", "rxjs": "^6.3.3", "rxjs-compat": "^6.2.1", "zone.js": "~0.8.26" }, "devDependencies": { "@angular-devkit/build-angular": "~0.6.8", "@angular/cli": "^6.1.2", "@angular/compiler-cli": "6.1.9", "@angular/language-service": "6.1.9", "@types/hammerjs": "^2.0.35", "@types/jasmine": "^2.8.6", "@types/jasminewd2": "~2.0.2", "@types/node": "^9.4.7", "codelyzer": "^4.2.1", "igniteui-angular": "^6.1.0", "jasmine-core": "~2.9.1", "jasmine-spec-reporter": "~4.2.1", "karma": "^2.0.5", "karma-chrome-launcher": "~2.2.0", "karma-cli": "~1.0.1", "karma-coverage-istanbul-reporter": "^1.4.2", "karma-jasmine": "^1.1.2", "karma-jasmine-html-reporter": "^0.2.2", "protractor": "^5.3.1", "ts-node": "~4.1.0", "tslint": "~5.9.1", "typescript": "^2.9.0"

Charlyo avatar Sep 27 '18 18:09 Charlyo

@Charlyo @Andrii-A Did you check whether you've installed angular as a global package and if it's upgraded to 6.x?

npm ls --global --depth=0

iamjoyce avatar Sep 28 '18 05:09 iamjoyce

@Charlyo @Andrii-A Did you check whether you've installed angular as a global package and if it's upgraded to 6.x?

npm ls --global --depth=0

This is the output that I get

/usr/local/lib ├── @angular/[email protected] ├── [email protected] -> /Users/charlyo/ANIS/interface └── [email protected]

npm ERR! peer dep missing: @angular/core@^5.0 || ^4.0 || ^2.0, required by [email protected] npm ERR! peer dep missing: typescript@~2.4.0 || ~2.5.0 || ~2.6.0 || ~2.7.0, required by @ngtools/[email protected]

Charlyo avatar Sep 28 '18 10:09 Charlyo

Same here (Angular 6.1.10):

$ ng -v

     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/


Angular CLI: 6.2.4
Node: 8.11.1
OS: win32 x64
Angular: 6.1.10

Ouput:

i 「wdm」: Compiled successfully.
i 「wdm」: Compiling...
C:\PROJECT_PATH\node_modules\enhanced-resolve\lib\CachedInputFileSystem.js:92
                                        throw data[0];
                                        ^

Error: ENOENT: no such file or directory, stat 'C:\PROJECT_PATH\src\app\@shared\sr-only\sr-only.component.ngfactory.js'
    at Object.fs.statSync (fs.js:948:11)

odahcam avatar Oct 11 '18 20:10 odahcam

Workaround [email protected] Workaround [email protected]

smasala avatar Oct 12 '18 18:10 smasala

I have the same issue with [email protected] and [email protected]

It fails with error Error: ENOENT: no such file or directory, stat '/Users/sergeyf/job/case-management-frontend/src/app/shared/components/cost-center-image/cost-center-image.component.ngfactory.js'

What's unusual here we use an inline template, not standalone. Might be this a problem?

https://github.com/angular/angular-cli/issues/12260#issuecomment-429831070 this helped me out

fetis avatar Oct 16 '18 08:10 fetis

In our case, we were optimizing the ng serve which threw similar error message.

Instead of:

           "dev": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.dev.ts"
                }
              ],
              "optimization": false,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "aot": true,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true
            },

Use:

           "localdev": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.localdev.ts"
                }
              ]
            }

turoo12 avatar Oct 16 '18 16:10 turoo12

https://github.com/angular/quickstart/issues/365#issuecomment-448161214 plz see the issue reply me.

selvam326 avatar Dec 18 '18 10:12 selvam326

ERROR in ./src/main.ts Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' in 'D:\2019\DCubeBillingSystem\DCubeHotelSystem\app\src' ERROR in Error: Cannot determine the module for class ReportDashboardComponent in D:/2019/DCubeBillingSystem/DCubeHotelSystem/app/src/app/components/ReportDashboard/reportdashboard.component.ts! Add ReportDashboardComponent to the NgModule to fix it.

lincolnmandal avatar Dec 25 '18 05:12 lincolnmandal

Issue still exists when ng build --aot. Issue still exists when ng serve --aot.

Angular CLI: 7.3.2
Node: 10.0.0
OS: darwin x64
Angular: 7.2.5
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.13.2
@angular-devkit/build-angular     0.13.2
@angular-devkit/build-optimizer   0.13.2
@angular-devkit/build-webpack     0.13.2
@angular-devkit/core              7.3.2
@angular-devkit/schematics        7.3.2
@angular/cli                      7.3.2
@ngtools/webpack                  7.3.2
@schematics/angular               7.3.2
@schematics/update                0.13.2
rxjs                              6.4.0
typescript                        3.2.4
webpack                           4.29.0

artuska avatar Feb 20 '19 11:02 artuska

I have the same issue as @artuska with the same specs.

Angular CLI: 7.3.3
Node: 8.12.0
OS: win32 x64
Angular: 7.2.6
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.13.3
@angular-devkit/build-angular     0.13.3
@angular-devkit/build-optimizer   0.13.3
@angular-devkit/build-webpack     0.13.3
@angular-devkit/core              0.7.5
@angular-devkit/schematics        0.7.5
@angular/cdk                      7.3.3
@angular/cli                      7.3.3
@angular/flex-layout              7.0.0-beta.23
@angular/material                 7.3.3
@ngtools/json-schema              1.1.0
@ngtools/webpack                  7.3.3
@schematics/angular               7.3.3
@schematics/update                0.13.3
ng-packagr                        4.7.1
rxjs                              6.4.0
typescript                        3.2.4
webpack                           4.29.0

JWBrownie avatar Feb 22 '19 23:02 JWBrownie

@JWBrownie If you have this type of error probably you have upgraded from Angular 5 to 6 or 7.

Replace "rootDir": "./src", in your tsconfig.json file to "rootDir": "./", or just remove this parameter completely.

artuska avatar Feb 23 '19 08:02 artuska

See also https://github.com/angular/angular-cli/issues/13721

artuska avatar Feb 23 '19 08:02 artuska

@artuska VERIFIED. Worked for me. Thank you from NYC.

gatsbyz avatar Feb 27 '19 02:02 gatsbyz

Still having this issue on Angular 7.2 Only with ng build or serve --aot or --prod, I get: .ngfactory.js Module not found Any help? I see a 'fixed by Ivy' tag applied - would I have to wait for Ivy?

andrewantar avatar Mar 18 '19 22:03 andrewantar