weixin_39733943
2021-01-12 18:51 阅读 7

"Cannot convert undefined or null to object" when upgrading to 8.

Please make sure you have read the submission guidelines before posting an issue

Prerequisites

Please answer the following questions for yourself before submitting an issue. YOU MAY DELETE THE PREREQUISITES SECTION.

  • [x] I am running the latest version
  • [x] I checked the documentation and found no answer
  • [x] I checked to make sure that this issue has not already been filed
  • [x] I'm reporting the issue to the correct repository (not related to Angular, AngularCLI or any dependency)

Expected Behavior

Should be able to upgrade using yarn upgrade.

Current Behavior

it fails with

Cannot convert undefined or null to object

looking through the filed issues, it appears that manually doing

bash
./node_modules/.bin/ng update /schematics --from 7.6.0 --to 8 --migrate-only

should do the trick. But it does not.

Failure Information (for bugs)

So I went ahead and tried to debug to pin point where exactly is the issue. it appears at updateBuilders function call at

https://github.com/nrwl/nx/blob/master/packages/schematics/migrations/update-8-0-0/update-8-0-0.ts#L385

which further calls updateJsonInTree and readJsonInTree implying that we are not returning any json from the callback. I tried debugging, and verified that both my angular.json and package.json are in correct format. I am adding my angular.json for furthur inspection.

json
{
  "$schema": "./node_modules//cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "",
  "projects": {
    "core": {
      "root": "apps/core/",
      "sourceRoot": "apps/core/src",
      "projectType": "application",
      "prefix": "smp",
      "schematics": {
        "/schematics:component": {
          "style": "scss"
        }
      },
      "architect": {
        "build": {
          "builder": "-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist/apps/core",
            "index": "apps/core/src/index.html",
            "main": "apps/core/src/main.ts",
            "polyfills": "apps/core/src/polyfills.ts",
            "tsConfig": "apps/core/tsconfig.app.json",
            "assets": [
              "apps/core/src/favicon.ico",
              {
                "input": "libs/theme/assets",
                "glob": "**/*",
                "output": "assets"
              }
            ],
            "styles": ["apps/core/src/styles.scss"],
            "scripts": [],
            "es5BrowserSupport": true
          },
          "configurations": {
            "hmr": {
              "fileReplacements": [
                {
                  "replace": "libs/common/src/environments/environment.ts",
                  "with": "libs/common/src/environments/environment.hmr.ts"
                }
              ]
            },
            "production": {
              "fileReplacements": [
                {
                  "replace": "libs/common/src/environments/environment.ts",
                  "with": "libs/common/src/environments/environment.prod.ts"
                }
              ],
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "aot": true,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "budgets": [
                {
                  "type": "initial",
                  "maximumWarning": "2mb",
                  "maximumError": "5mb"
                }
              ]
            }
          }
        },
        "serve": {
          "builder": "-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "core:build"
          },
          "configurations": {
            "hmr": {
              "hmr": true,
              "browserTarget": "core:build:hmr"
            },
            "production": {
              "browserTarget": "core:build:production"
            }
          }
        },
        "extract-i18n": {
          "builder": "-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "core:build"
          }
        },
        "lint": {
          "builder": "-devkit/build-angular:tslint",
          "options": {
            "tsConfig": ["apps/core/tsconfig.app.json", "apps/core/tsconfig.spec.json"],
            "exclude": ["**/node_modules/**"]
          }
        },
        "test": {
          "builder": "/builders:jest",
          "options": {
            "jestConfig": "apps/core/jest.config.js",
            "tsConfig": "apps/core/tsconfig.spec.json",
            "setupFile": "apps/core/src/test-setup.ts"
          }
        }
      }
    },
    "core-e2e": {
      "root": "apps/core-e2e",
      "projectType": "application",
      "prefix": "",
      "architect": {
        "e2e": {
          "builder": "/builders:cypress",
          "options": {
            "cypressConfig": "apps/core-e2e/cypress.json",
            "tsConfig": "apps/core-e2e/tsconfig.e2e.json",
            "devServerTarget": "core:serve"
          },
          "configurations": {
            "production": {
              "devServerTarget": "core:serve:production"
            }
          }
        },
        "lint": {
          "builder": "-devkit/build-angular:tslint",
          "options": {
            "tsConfig": "apps/core-e2e/tsconfig.e2e.json",
            "exclude": ["**/node_modules/**"]
          }
        }
      }
    },
    "common": {
      "root": "libs/common",
      "sourceRoot": "libs/common/src",
      "projectType": "library",
      "prefix": "smp",
      "architect": {
        "lint": {
          "builder": "-devkit/build-angular:tslint",
          "options": {
            "tsConfig": ["libs/common/tsconfig.lib.json", "libs/common/tsconfig.spec.json"],
            "exclude": ["**/node_modules/**"]
          }
        },
        "test": {
          "builder": "/builders:jest",
          "options": {
            "jestConfig": "libs/common/jest.config.js",
            "tsConfig": "libs/common/tsconfig.spec.json"
          }
        }
      },
      "schematics": {
        "/schematics:component": {
          "styleext": "scss"
        }
      }
    },
    "auth": {
      "root": "libs/auth",
      "sourceRoot": "libs/auth/src",
      "projectType": "library",
      "prefix": "smp-auth",
      "architect": {
        "lint": {
          "builder": "-devkit/build-angular:tslint",
          "options": {
            "tsConfig": ["libs/auth/tsconfig.lib.json", "libs/auth/tsconfig.spec.json"],
            "exclude": ["**/node_modules/**"]
          }
        },
        "test": {
          "builder": "/builders:jest",
          "options": {
            "jestConfig": "libs/auth/jest.config.js",
            "tsConfig": "libs/auth/tsconfig.spec.json",
            "setupFile": "libs/auth/src/test-setup.ts"
          }
        }
      },
      "schematics": {
        "/schematics:component": {
          "styleext": "scss"
        }
      }
    },
    "submissions": {
      "root": "libs/submissions",
      "sourceRoot": "libs/submissions/src",
      "projectType": "library",
      "prefix": "smp-submissions",
      "architect": {
        "lint": {
          "builder": "-devkit/build-angular:tslint",
          "options": {
            "tsConfig": ["libs/submissions/tsconfig.lib.json", "libs/submissions/tsconfig.spec.json"],
            "exclude": ["**/node_modules/**"]
          }
        },
        "test": {
          "builder": "/builders:jest",
          "options": {
            "jestConfig": "libs/submissions/jest.config.js",
            "tsConfig": "libs/submissions/tsconfig.spec.json",
            "setupFile": "libs/submissions/src/test-setup.ts"
          }
        }
      },
      "schematics": {
        "/schematics:component": {
          "styleext": "scss"
        }
      }
    },
    "theme": {
      "root": "libs/theme",
      "projectType": "library"
    },
    "ui": {
      "root": "libs/ui",
      "sourceRoot": "libs/ui/src",
      "projectType": "library",
      "prefix": "smp",
      "architect": {
        "lint": {
          "builder": "-devkit/build-angular:tslint",
          "options": {
            "tsConfig": ["libs/ui/tsconfig.lib.json", "libs/ui/tsconfig.spec.json"],
            "exclude": ["**/node_modules/**"]
          }
        },
        "test": {
          "builder": "/builders:jest",
          "options": {
            "jestConfig": "libs/ui/jest.config.js",
            "tsConfig": "libs/ui/tsconfig.spec.json",
            "setupFile": "libs/ui/src/test-setup.ts"
          }
        }
      },
      "schematics": {
        "/schematics:component": {
          "styleext": "scss"
        }
      }
    },
    "rest": {
      "root": "libs/rest",
      "sourceRoot": "libs/rest/src",
      "projectType": "library",
      "prefix": "smp",
      "architect": {
        "lint": {
          "builder": "-devkit/build-angular:tslint",
          "options": {
            "tsConfig": ["libs/rest/tsconfig.lib.json", "libs/rest/tsconfig.spec.json"],
            "exclude": ["**/node_modules/**"]
          }
        },
        "test": {
          "builder": "/builders:jest",
          "options": {
            "jestConfig": "libs/rest/jest.config.js",
            "tsConfig": "libs/rest/tsconfig.spec.json"
          }
        }
      },
      "schematics": {
        "/schematics:component": {
          "styleext": "scss"
        }
      }
    },
    "pipes": {
      "root": "libs/pipes",
      "sourceRoot": "libs/pipes/src",
      "projectType": "library",
      "prefix": "smp",
      "architect": {
        "lint": {
          "builder": "-devkit/build-angular:tslint",
          "options": {
            "tsConfig": ["libs/pipes/tsconfig.lib.json", "libs/pipes/tsconfig.spec.json"],
            "exclude": ["**/node_modules/**"]
          }
        },
        "test": {
          "builder": "/builders:jest",
          "options": {
            "jestConfig": "libs/pipes/jest.config.js",
            "tsConfig": "libs/pipes/tsconfig.spec.json",
            "setupFile": "libs/pipes/src/test-setup.ts"
          }
        }
      },
      "schematics": {
        "/schematics:component": {
          "styleext": "scss"
        }
      }
    }
  },
  "cli": {
    "warnings": {
      "typescriptMismatch": false,
      "versionMismatch": false
    },
    "defaultCollection": "/schematics"
  },
  "schematics": {
    "/schematics:application": {
      "style": "scss"
    },
    "/schematics:library": {
      "style": "scss",
      "framework": "angular"
    }
  },
  "defaultProject": "core"
}

Any helpers in this regard would be appreciated. thanks.

该提问来源于开源项目:nrwl/nx

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

4条回答 默认 最新

  • weixin_39979516 weixin_39979516 2021-01-12 18:51

    Thanks for reporting this issue!

    It is a bug but to get around it, you can create an architect: {} field for the theme project.

    点赞 评论 复制链接分享
  • weixin_39733943 weixin_39733943 2021-01-12 18:51

    thankyou guys.

    点赞 评论 复制链接分享
  • weixin_39972996 weixin_39972996 2021-01-12 18:51

    I just experienced this same issue today but for a different reason.

    My root tsconfig.json did not have a value for compilerOptions.paths because I had previously removed it. I have one app and no libs so far.

    I tried adding a lib and got:

    Cannot convert undefined or null to object

    After debugging the library.js script in node_modules//angular..., I found that the updateTsConfig rule is the source of the bug. It assumes that tsconfig.json already has a value for compilerOptions.paths.

    https://github.com/nrwl/nx/blob/d9084a08abe8e5885d255df30256dbb303915169/packages/angular/src/schematics/library/library.ts#L390-L396

    There should be a check there that provides a default value for compilerOptions.paths if one does not exist.

    In the meantime, for anyone who experiences this issue, simply add an empty object for compilerOptions.paths to your root tsconfig.json file before running ng g /angular:lib ...:

    {
        "compilerOptions": {
            // ...
            "paths": {}
        }
    }
    
    点赞 评论 复制链接分享
  • weixin_39687189 weixin_39687189 2021-01-12 18:51

    Thank you! It worked!

    点赞 评论 复制链接分享

相关推荐