bikecoders / ngx-deploy-npm

Nx plugin to publish any JS library to NPM with one command
https://www.npmjs.com/package/ngx-deploy-npm
MIT License
108 stars 13 forks source link

Error: context.projectGraph is undefined #494

Closed eamell closed 1 year ago

eamell commented 1 year ago

I am setting up ngx-deploy-npm on an existing library project. We have been just using npm publish to publish the library to a custom repository (Sonatype Nexus). I installed ngx-deploy-npm via npm install --save-dev ngx-deploy-npm followed by nx generate ngx-deploy-npm:install and that appears to have worked successfully.

However when I run nx deploy --dry-run I get the following error:

[NX] Angular devkit readJsonWorkspace fell back to Nx workspaces logic
Workspace extension with invalid name (npmScope) found.
Workspace extension with invalid name (tasksRunnerOptions) found.
Workspace extension with invalid name (affected) found.
Workspace extension with invalid name (targetDefaults) found.
Project extension with invalid name (files) found.
Error: context.projectGraph is undefined
    at /home/eamell/projects/commons/<project name>/node_modules/ngx-deploy-npm/src/executors/deploy/actions.js:11:19
    at Generator.next (<anonymous>)
    at /home/eamell/projects/commons/<project name>/node_modules/tslib/tslib.js:167:75
    at new Promise (<anonymous>)
    at Object.__awaiter (/home/eamell/projects/commons/<project name>/node_modules/tslib/tslib.js:163:16)
    at deploy (/home/eamell/projects/commons/<project name>/node_modules/ngx-deploy-npm/src/executors/deploy/actions.js:8:20)
    at /home/eamell/projects/commons/<project name>/node_modules/ngx-deploy-npm/src/executors/deploy/executor.js:14:41
    at Generator.next (<anonymous>)
    at /home/eamell/projects/commons/<project name>/node_modules/tslib/tslib.js:167:75
    at new Promise (<anonymous>)
Error when trying to publish the library

Here is the result of nx report:

>  NX   Report complete - copy this into the issue template

   Node : 14.21.3
   OS   : linux x64
   npm  : 6.14.18

   @nrwl/schematics : Not Found
   @nrwl/storybook : 14.5.4
   @nrwl/web : 14.5.4
   @nrwl/workspace : 14.5.4
   typescript : 4.7.4
   ---------------------------------------
   Community plugins:
         @ngrx/data: 14.0.2
         @ngrx/effects: 14.0.2
         @ngrx/entity: 14.0.2
         @ngrx/router-store: 14.0.2
         @ngrx/store: 14.0.2
         @ngrx/store-devtools: 14.0.2
         rxjs: 6.6.2
         ng-mocks: 14.7.0
         ngx-deploy-npm: 5.1.0
         nx-stylelint: 11.2.1

I also tried ngx-deploy-npm versions 4.3.11 (which gave me a completely different error), 5.0.0, and 5.2.0 - 5.1.0 was my last attempt and I'll most likely go back to 5.2.0 since they all had the same result. Playing around when I commented out the lines in actions.js where it does the check for context.projectGraph the dry run went through successfully. I am confident something is wrong with my configuration but I am not really sure what it could be.

Here is my root package.json:

{
  "name": "<my project>-app",
  "version": "2.0.2",
  "scripts": {
    "ng": "ng",
    "postinstall": "ngcc --properties es2020 browser module main",
    "start": "${NG_CLI:-nx} serve",
    "build": "${NG_CLI:-nx} build",
    "build:<project name>:prod": "${NG_CLI:-nx} build <project name> --prod",
    "lint": "${NG_CLI:-nx} lint",
    "test": "${NG_CLI:-nx} test",
    "test:<project name>": "${NG_CLI:-nx} test <project name> --coverage",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@alfresco/aca-shared": "2.0.1",
    "@alfresco/adf-content-services": "5.0.1",
    "@alfresco/adf-core": "5.0.1",
    "@alfresco/adf-extensions": "5.0.1",
    "@alfresco/adf-process-services": "5.0.1",
    "@alfresco/adf-process-services-cloud": "5.0.1",
    "@alfresco/js-api": "5.0.0",
    "@angular/animations": "14.1.3",
    "@angular/cdk": "14.1.3",
    "@angular/common": "14.1.3",
    "@angular/compiler": "14.1.3",
    "@angular/core": "14.1.3",
    "@angular/flex-layout": "10.0.0-beta.32",
    "@angular/forms": "14.1.3",
    "@angular/material": "14.1.3",
    "@angular/material-moment-adapter": "14.1.3",
    "@angular/platform-browser": "14.1.3",
    "@angular/platform-browser-dynamic": "14.1.3",
    "@angular/router": "14.1.3",
    "@mat-datetimepicker/core": "^9.0.68",
    "@mat-datetimepicker/moment": "^9.0.68",
    "@ngrx/data": "14.0.2",
    "@ngrx/effects": "14.0.2",
    "@ngrx/entity": "14.0.2",
    "@ngrx/router-store": "14.0.2",
    "@ngrx/store": "14.0.2",
    "@ngrx/store-devtools": "14.0.2",
    "@ngx-translate/core": "13.0.0",
    "@nrwl/angular": "14.5.4",
    "file-saver": "2.0.2",
    "minimatch-browser": "1.0.0",
    "moment": "^2.29.4",
    "moment-es6": "1.0.0",
    "node-sass": "^8.0.0",
    "pdfjs-dist": "2.4.456",
    "rxjs": "6.6.2",
    "tslib": "^2.0.0",
    "xlsx": "^0.18.5",
    "zone.js": "~0.11.4"
  },
  "devDependencies": {
    "@alfresco/adf-cli": "5.0.1",
    "@alfresco/adf-testing": "5.0.1",
    "@angular-devkit/build-angular": "14.1.3",
    "@angular-eslint/eslint-plugin": "14.0.3",
    "@angular-eslint/eslint-plugin-template": "14.0.3",
    "@angular-eslint/template-parser": "14.0.3",
    "@angular/cli": "~14.1.0",
    "@angular/compiler-cli": "14.1.3",
    "@angular/language-service": "~14.1.1",
    "@nrwl/cli": "14.5.4",
    "@nrwl/devkit": "^14.5.4",
    "@nrwl/eslint-plugin-nx": "14.5.4",
    "@nrwl/jest": "14.5.4",
    "@nrwl/linter": "14.5.4",
    "@nrwl/nx-plugin": "14.5.4",
    "@nrwl/workspace": "14.5.4",
    "@types/jasmine": "4.0.3",
    "@types/jasminewd2": "2.0.8",
    "@types/jest": "27.4.1",
    "@types/lodash": "^4.14.191",
    "@types/node": "14.14.33",
    "@typescript-eslint/eslint-plugin": "^5.29.0",
    "@typescript-eslint/parser": "^5.29.0",
    "codelyzer": "^6.0.0",
    "eslint": "~8.15.0",
    "eslint-config-prettier": "8.1.0",
    "jasmine-ajax": "3.2.0",
    "jasmine-auto-spies": "^6.9.9",
    "jasmine-core": "4.2.0",
    "jasmine-marbles": "0.8.4",
    "jasmine-reporters": "^2.4.0",
    "jasmine-spec-reporter": "7.0.0",
    "jest": "27.5.1",
    "jest-environment-jsdom": "27.2.3",
    "jest-preset-angular": "11.1.2",
    "karma": "6.4.0",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~3.0.3",
    "karma-jasmine": "5.1.0",
    "karma-jasmine-ajax": "0.1.13",
    "karma-jasmine-html-reporter": "2.0.0",
    "karma-junit-reporter": "^2.0.1",
    "karma-mocha-reporter": "^2.2.5",
    "ng-mocks": "^14.7.0",
    "ng-packagr": "~14.1.0",
    "ngx-deploy-npm": "5.1.0",
    "nx": "14.5.4",
    "nx-stylelint": "^11.2.0",
    "postcss": "^8.4.5",
    "postcss-import": "~14.1.0",
    "postcss-preset-env": "~7.5.0",
    "postcss-url": "~10.1.3",
    "protractor": "~7.0.0",
    "scss-bundle": "3.1.2",
    "ts-jest": "27.1.4",
    "ts-mockito": "^2.6.1",
    "ts-node": "10.8.2",
    "typescript": "4.7.4",
    "wallaby-webpack": "^3.9.16"
  }
}

My angular.json:

{
  "$schema": "./node_modules/nx/schemas/nx-schema.json",
  "version": 2,
  "newProjectRoot": "projects",
  "projects": {
    "<project name>": {
      "$schema": "../../node_modules/nx/schemas/project-schema.json",
      "projectType": "library",
      "root": "projects/<project name>",
      "sourceRoot": "projects/<project name>/src",
      "prefix": "lib",
      "targets": {
        "build": {
          "executor": "@nrwl/angular:package",
          "outputs": [
            "dist/projects/<project name>"
          ],
          "options": {
            "project": "projects/<project name>/ng-package.json"
          },
          "configurations": {
            "production": {
              "tsConfig": "projects/<project name>/tsconfig.lib.prod.json"
            },
            "development": {
              "tsConfig": "projects/<project name>/tsconfig.lib.json"
            }
          },
          "defaultConfiguration": "production"
        },
        "test": {
          "executor": "@nrwl/jest:jest",
          "outputs": [
            "coverage/projects/<project name>"
          ],
          "options": {
            "jestConfig": "projects/<project name>/jest.config.ts",
            "passWithNoTests": true
          }
        },
        "lint": {
          "executor": "@nrwl/linter:eslint",
          "options": {
            "lintFilePatterns": [
              "projects/<project name>/**/*.ts",
              "projects/<project name>/**/*.html"
            ]
          }
        },
        "deploy": {
          "executor": "ngx-deploy-npm:deploy",
          "options": {
            "access": "public",
            "buildTarget": "production"
          }
        }
      },
      "tags": []
    }
  }
}

I will go back to using npm publish however ngx-deploy-npm is a cleaner solution as it doesn't require me to have my CI pipeline CD into an the distribution directory to run the publish from there.

Any help would be much appreciated.

dianjuar commented 1 year ago

Thank you so much for taking the time to explain your problem in detail.

I firmly believe this is an Nx V14.5.4 error. V14.5.8 was the closest version to yours that I could detect the error is not there.

I suggest doing nx migrate 14.5.8 (I believe that's the command) to upgrade your Nx workspace to that specific version. Typically, when between fix versions, there are no migrations to run, so the transition should be seamless.


I want to apologize for the delayed response. I was busy with some other maintenance chores on this project.

dianjuar commented 1 year ago

If you're curious about how I realize that, here is the explanation:

First, I saw nothing wrong with your configuration, so I thought it was an Nx issue. I have a command to create an Nx Workspace with a specific version to make manual tests (npx nx create-nx-workspace ngx-deploy-npm VERSION). So it's easy and fast for me to test whether the plugin works correctly on a specific version. I tried your version and had the same problem so, I started with your workspace version and increased the version until the error was gone.

That is how I could determine the solution.

dianjuar commented 1 year ago

I'm going to close this one.

If you apply my suggestion and the problem remains, please let me know to figure it out together.

eamell commented 1 year ago

@dianjuar no worries on the delay, this is an open source project so I generally expect that people are doing maintenance in their spare time.

Thank you this worked and thank you for the explanation I found it enlightening.