发生未处理的异常:项目不存在。角 s-s-r

Posted

技术标签:

【中文标题】发生未处理的异常:项目不存在。角 s-s-r【英文标题】:An unhandled exception occurred: Project does not exist. Angular s-s-r 【发布时间】:2021-06-12 03:47:05 【问题描述】:

我在我的 Angular 项目中实现了 Angular 通用,但之后每当我构建项目时,我都会遇到错误

[错误] 错误:项目不存在。 在 WorkspaceNodeModulesArchitectHost.findProjectTarget (/home/atif/Desktop/Code/BlogFE/blogui/BlogApp/node_modules/@angular/cli/node_modules/@angular-devkit/architect/node/node-modules-architect-host.js:122: 19) 在 WorkspaceNodeModulesArchitectHost.getBuilderNameForTarget (/home/atif/Desktop/Code/BlogFE/blogui/BlogApp/node_modules/@angular/cli/node_modules/@angular-devkit/architect/node/node-modules-architect-host.js:23: 39) 在 RunCommand.runSingleTarget (/home/atif/Desktop/Code/BlogFE/blogui/BlogApp/node_modules/@angular/cli/models/architect-command.js:174:55) 在 RunCommand.runArchitectTarget (/home/atif/Desktop/Code/BlogFE/blogui/BlogApp/node_modules/@angular/cli/models/architect-command.js:217:35) 在 RunCommand.run (/home/atif/Desktop/Code/BlogFE/blogui/BlogApp/node_modules/@angular/cli/commands/run-impl.js:14:25) 在 RunCommand.validateAndRun (/home/atif/Desktop/Code/BlogFE/blogui/BlogApp/node_modules/@angular/cli/models/command.js:134:39) 在异步 Object.runCommand (/home/atif/Desktop/Code/BlogFE/blogui/BlogApp/node_modules/@angular/cli/models/command-runner.js:201:24) 在 async default_1 (/home/atif/Desktop/Code/BlogFE/blogui/BlogApp/node_modules/@angular/cli/lib/cli/index.js:62:31)

angular.json 文件


  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": 
    "blogapp": 
      "projectType": "application",
      "schematics": 
        "@schematics/angular:component": 
          "style": "scss"
        
      ,
      "root": "",
      "sourceRoot": "src",
      "prefix": "app",
      "architect": 
        "build": 
          "builder": "@angular-devkit/build-angular:browser",
          "options": 
            "outputPath": "dist/browser",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "tsconfig.app.json",
            "aot": true,
            "assets": [
              "src/favicon.ico",
              "src/assets",
              "src/sitemap.xml",
              "src/robots.txt"
            ],
            "styles": [
              "node_modules/bootstrap/dist/css/bootstrap.min.css",
              "node_modules/font-awesome/css/font-awesome.min.css",
              "src/styles.scss"
            ],
            "scripts": [
              "./node_modules/jquery/dist/jquery.min.js",
              "node_modules/bootstrap/dist/js/bootstrap.min.js"
            ]
          ,
          "configurations": 
            "production": 
              "fileReplacements": [
                
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                
              ],
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "budgets": [
                
                  "type": "initial",
                  "maximumWarning": "2mb",
                  "maximumError": "10mb"
                ,
                
                  "type": "anyComponentStyle",
                  "maximumWarning": "6kb",
                  "maximumError": "10kb"
                
              ]
            
          
        ,
        "serve": 
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": 
            "browserTarget": "blogapp:build"
          ,
          "configurations": 
            "production": 
              "browserTarget": "blogapp:build:production"
            
          
        ,
        "extract-i18n": 
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": 
            "browserTarget": "blogapp:build"
          
        ,
        "test": 
          "builder": "@angular-devkit/build-angular:karma",
          "options": 
            "main": "src/test.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "tsconfig.spec.json",
            "karmaConfig": "karma.conf.js",
            "assets": [
              "src/favicon.ico",
              "src/assets",
              "src/sitemap.xml",
              "src/robots.txt"
            ],
            "styles": [
              "src/styles.scss"
            ],
            "scripts": []
          
        ,
        "lint": 
          "builder": "@angular-devkit/build-angular:tslint",
          "options": 
            "tsConfig": [
              "tsconfig.app.json",
              "tsconfig.spec.json",
              "e2e/tsconfig.json"
            ],
            "exclude": [
              "**/node_modules/**"
            ]
          
        ,
        "e2e": 
          "builder": "@angular-devkit/build-angular:protractor",
          "options": 
            "protractorConfig": "e2e/protractor.conf.js",
            "devServerTarget": "blogapp:serve"
          ,
          "configurations": 
            "production": 
              "devServerTarget": "blogapp:serve:production"
            
          
        ,
        "server": 
          "builder": "@angular-devkit/build-angular:server",
          "options": 
            "outputPath": "dist/server",
            "main": "src/main.server.ts",
            "tsConfig": "tsconfig.server.json"
          ,
          "configurations": 
            "production": 
              "outputHashing": "media",
              "fileReplacements": [
                
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                
              ],
              "sourceMap": false,
              "optimization": true
            ,
            "serverless": 
              "fileReplacements": [
                
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.serverless.ts"
                
              ]
            
          
        
      
    
  ,
  "defaultProject": "blogapp"

package.json 文件


  "name": "blogapp",
  "version": "0.0.0",
  "scripts": 
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "compile:server": "webpack --config webpack.server.config.js --progress --colors",
    "serve:s-s-r": "node dist/server",
    "build:s-s-r": "ng build --prod && ng run universal-website:server:production && npm run compile:server",
    "build:client-and-server-bundles": "ng build --prod && ng run blogapp:server:production --bundleDependencies all",
    "server": "node local.js",
    "build:prod": "npm run build:browser:prod && npm run build:server:prod",
    "serve:prerender": "node static.js",
    "build:prerender": "npm run build:prod && node dist/prerender.js",
    "build:browser:prod": "ng build --prod",
    "build:browser:serverless": "ng build --prod --base-href /production/",
    "build:serverless": "npm run build:browser:serverless && npm run build:server:serverless",
    "build:prod:deploy": "npm run build:prod && npm run deploy",
    "build:serverless:deploy": "npm run build:serverless && npm run deploy",
    "deploy": "serverless deploy",
    "build:server:prod": "ng run universal-website:server:production && npm run compile:server",
    "build:server:serverless": "ng run universal-website:server:serverless && npm run compile:server",
    "terminate": "serverless remove"
  ,
  "private": true,
  "dependencies": 
    "@angular-devkit/schematics": "^9.1.0",
    "@angular/animations": "~9.1.6",
    "@angular/common": "~9.1.6",
    "@angular/compiler": "~9.1.6",
    "@angular/core": "~9.1.6",
    "@angular/forms": "~9.1.6",
    "@angular/platform-browser": "~9.1.6",
    "@angular/platform-browser-dynamic": "~9.1.6",
    "@angular/platform-server": "~9.1.6",
    "@angular/router": "~9.1.6",
    "@ng-toolkit/serverless": "^8.1.0",
    "@ng-toolkit/universal": "^8.0.3",
    "@nguniversal/common": "8.1.0",
    "@nguniversal/express-engine": "v8.2.6",
    "@nguniversal/module-map-ngfactory-loader": "v8.2.6",
    "@schematics/angular": "^9.1.0",
    "@syncfusion/ej2-angular-richtexteditor": "^18.2.56",
    "@vendia/serverless-express": "^4.3.4",
    "aws-sdk": "^2.797.0",
    "aws-serverless-express": "^3.3.6",
    "bootstrap": "^3.3.7",
    "cors": "^2.8.5",
    "domino": "^2.1.3",
    "express": "^4.15.2",
    "font-awesome": "^4.7.0",
    "jquery": "^3.5.1",
    "ng-lazyload-image": "^9.1.0",
    "ngx-spinner": "^10.0.1",
    "rxjs": "~6.5.4",
    "tslib": "^1.10.0",
    "web-animations-js": "^2.3.2",
    "zone.js": "~0.10.2"
  ,
  "devDependencies": 
    "@angular-devkit/build-angular": "^0.901.15",
    "@angular/cli": "^9.1.6",
    "@angular/compiler-cli": "~9.1.6",
    "@types/express": "^4.17.0",
    "@types/jasmine": "~3.5.0",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "^12.19.6",
    "codelyzer": "^5.1.2",
    "jasmine-core": "~3.5.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~5.0.0",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage-istanbul-reporter": "~2.1.0",
    "karma-jasmine": "~3.0.1",
    "karma-jasmine-html-reporter": "^1.4.2",
    "opencollective": "^1.0.3",
    "protractor": "~5.4.3",
    "serverless": "^2.29.0",
    "serverless-api-compression": "^1.0.1",
    "serverless-apigw-binary": "^0.4.4",
    "ts-loader": "^6.2.1",
    "ts-node": "~8.3.0",
    "tslint": "~6.1.0",
    "typescript": "~3.8.3",
    "webpack-cli": "^3.3.10"
  



基本上每当我运行 npm run build:s-s-r 时都会出现此错误

【问题讨论】:

【参考方案1】:

通过运行命令在 package.json 中完成代码更改,问题得到解决

ng 添加@ng-toolkit/universal

引用了错误的项目名称

"build:s-s-r": "ng build --prod && ng run **universal-website**:server:production && npm run compile:server"

我换成了

"build:s-s-r": "ng build --prod && ng run blogapp:server:production && npm run compile:server",

【讨论】:

以上是关于发生未处理的异常:项目不存在。角 s-s-r的主要内容,如果未能解决你的问题,请参考以下文章

Angular 和 .Net Core 项目 VS 2022:发生未处理的异常:项目 'Leon\AppData\Roaming\ASP.NET\https\<projectName>.p

Flutter:未处理的异常:错误状态:DocumentSnapshotPlatform中不存在字段

PHP - Codeigniter:未捕获的异常“PHPExcel_Reader_Exception”,消息“无法打开读取,文件不存在”

asp.net求助

Magento API 错误 --- SoapHeaderException: 程序“登录”不存在

Firebase 异常:对象不存在