简体   繁体   中英

ASP.NET Core 2 Angular 5 project template doesn't publish

I'm using this project template and everything was perfect so far. Using the dotnet run command the project starts, I can make changes in client side files and reload is working. Now as I have almost finished I try to make a publish with dotnet publish --configuration=Release and it throws the following error:

ERROR in ./src/main.ts                                                                                                                           
Module not found: Error: Can't resolve './app/app.module.ngfactory' in 'C:\Users\********\***\***\********\ClientApp\src'                 
resolve './app/app.module.ngfactory' in 'C:\Users\********\***\***\********\ClientApp\src'                                                
  using description file: C:\Users\********\***\***\********\ClientApp\package.json (relative path: ./src)                                
    Field 'browser' doesn't contain a valid alias configuration                                                                                  
  after using description file: C:\Users\********\***\***\********\ClientApp\package.json (relative path: ./src)                          
    using description file: C:\Users\********\***\***\********\ClientApp\package.json (relative path: ./src/app/app.module.ngfactory)     
      no extension                                                                                                                               
        Field 'browser' doesn't contain a valid alias configuration                                                                              
        C:\Users\********\***\***\********\ClientApp\src\app\app.module.ngfactory doesn't exist                                           
      .ts                                                                                                                                        
        Field 'browser' doesn't contain a valid alias configuration                                                                              
        C:\Users\********\***\***\********\ClientApp\src\app\app.module.ngfactory.ts doesn't exist                                        
      .js                                                                                                                                        
        Field 'browser' doesn't contain a valid alias configuration                                                                              
        C:\Users\********\***\***\********\ClientApp\src\app\app.module.ngfactory.js doesn't exist                                        
      as directory                                                                                                                               
        C:\Users\********\***\***\********\ClientApp\src\app\app.module.ngfactory doesn't exist                                           
[C:\Users\********\***\***\********\ClientApp\src\app\app.module.ngfactory]                                                               
[C:\Users\********\***\***\********\ClientApp\src\app\app.module.ngfactory.ts]                                                            
[C:\Users\********\***\***\********\ClientApp\src\app\app.module.ngfactory.js]                                                            
[C:\Users\********\***\***\********\ClientApp\src\app\app.module.ngfactory]                                                               
 @ ./src/main.ts 3:0-66                                                                                                                          
 @ multi ./src/main.ts                                                                                                                           

If I switch to the ./ClientApp folder and try ng build --extract-css --prod it gives the same result but I don't know what causes this? This error message means nothing to me.

./ClientApp/package.json

  "name": "*******",
  "version": "0.9.0",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "ng serve --extract-css",
    "build": "ng build --extract-css",
    "build:ssr": "npm run build -- --app=ssr --output-hashing=media",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular-devkit/schematics": "0.0.40",
    "@angular/animations": "^5.0.0",
    "@angular/common": "^5.0.0",
    "@angular/compiler": "^5.0.0",
    "@angular/core": "^5.0.0",
    "@angular/forms": "^5.0.0",
    "@angular/http": "^5.0.0",
    "@angular/platform-browser": "^5.0.0",
    "@angular/platform-browser-dynamic": "^5.0.0",
    "@angular/platform-server": "^5.0.0",
    "@angular/router": "^5.0.0",
    "@ng-bootstrap/ng-bootstrap": "^1.0.0-beta.9",
    "@nguniversal/module-map-ngfactory-loader": "^5.0.0-beta.5",
    "aspnet-prerendering": "^3.0.1",
    "bootstrap": "^3.3.7",
    "core-js": "^2.4.1",
    "file-saver": "^1.3.3",
    "ng2-dragula": "^1.5.0",
    "ng2-file-upload": "^1.3.0",
    "ngx-bootstrap": "^2.0.1",
    "rxjs": "^5.5.2",
    "zone.js": "^0.8.14"
  },
  "devDependencies": {
    "@angular/cli": "1.6.0",
    "@angular/compiler-cli": "^5.0.0",
    "@angular/language-service": "^5.0.0",
    "@types/jasmine": "~2.5.53",
    "@types/jasminewd2": "~2.0.2",
    "@types/node": "~6.0.60",
    "codelyzer": "^4.0.1",
    "jasmine-core": "~2.6.2",
    "jasmine-spec-reporter": "~4.1.0",
    "karma": "~1.7.0",
    "karma-chrome-launcher": "~2.1.1",
    "karma-cli": "~1.0.1",
    "karma-coverage-istanbul-reporter": "^1.2.1",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.1.2",
    "ts-node": "~3.2.0",
    "tslint": "~5.7.0",
    "typescript": "~2.4.2"
  }

Update#1:

It builds with aot disabled: ng build --extract-css --prod --aot false

It's building with AOT disabled. The link @tomichel added describes some possible causes but for me it was some older client side libraries that isn't compatible with AOT. So disabling AOT for now solves it:

ng build --extract-css --prod --aot false

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM