nrwl / nx

Smart Monorepos · Fast CI
https://nx.dev
MIT License
23.52k stars 2.34k forks source link

generate lib fails with useless error #1044

Closed elliotmendiola closed 5 years ago

elliotmendiola commented 5 years ago

Expected Behavior

ng generate lib myLib should generate a lib named myLib

Current Behavior

After answering the questions needed to generate a lib I get the following error: Cannot convert undefined or null to object

Failure Information (for bugs)

[redacted]$ ng g lib shared --defaults
? In which directory should the library be generated? 
? Which module should import the library? 
? Which tags would you like to add to the library? (used for linting) 
Cannot convert undefined or null to object

Steps to Reproduce

Follow the nx example, but before generating a lib, drop an existing ionic app into the generated app

Nx Version @nrwl/nx: 7.5.1

nx.json

{
  "npmScope": "[redacted]",
  "implicitDependencies": {
    "angular.json": "*",
    "package.json": "*",
    "tsconfig.json": "*",
    "tslint.json": "*",
    "nx.json": "*"
  },
  "projects": {
    "mobile-app": {
      "tags": ["mobile"]
    },
    "mobile-app-e2e": {
      "tags": []
    }
  }
}

Angular CLI/build kit versions

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

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.11.4
@angular-devkit/build-angular     0.11.4
@angular-devkit/build-optimizer   0.11.4
@angular-devkit/build-webpack     0.11.4
@angular-devkit/core              7.2.1
@angular-devkit/schematics        7.2.1
@angular/cdk                      7.2.0
@ngtools/webpack                  7.1.4
@schematics/angular               7.2.1
@schematics/update                0.12.1
rxjs                              6.3.3
typescript                        3.3.1
webpack                           4.23.1

Angular.json

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "",
  "projects": {
    "mobile-app": {
      "root": "apps/mobile-app/",
      "sourceRoot": "apps/mobile-app/src",
      "projectType": "application",
      "prefix": "[redacted]",
      "schematics": {
        "@nrwl/schematics:component": {
          "style": "scss"
        }
      },
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "apps/mobile-app/dist",
            "index": "apps/mobile-app/src/index.html",
            "main": "apps/mobile-app/src/main.ts",
            "polyfills": "apps/mobile-app/src/polyfills.ts",
            "tsConfig": "apps/mobile-app/tsconfig.app.json",
            "assets": [
              {
                "glob": "**/*",
                "input": "apps/mobile-app/src/assets",
                "output": "assets"
              },
              {
                "glob": "**/*.svg",
                "input": "node_modules/ionicons/dist/ionicons/svg",
                "output": "./svg"
              },
              {
                "glob": "**/*.svg",
                "input": "node_modules/@ionic/angular/dist/ionic/svg",
                "output": "./svg"
              },
              {
                "glob": "**/*",
                "input": "apps/mobile-app/src/app/modules/pay/taxes/containers/withholding-form-iframe/iframe",
                "output": "withholding-form-iframe/iframe"
              },
              {
                "glob": "jquery.resize.js",
                "input": "node_modules/javascript-detect-element-resize",
                "output": "withholding-form-iframe/javascript-detect-element-resize"
              },
              {
                "glob": "**/*",
                "input": "./node_modules/[redacted]/assets/fonts/roboto/",
                "output": "./assets/fonts/roboto"
              },
              {
                "glob": "**/*.json",
                "input": "./node_modules/[redacted]/dist/COMMON",
                "output": "./assets/translations"
              },
              {
                "glob": "**/*.json",
                "input": "./node_modules/[redacted]/compiled",
                "output": "./assets/translations-nu"
              }
            ],
            "styles": ["apps/mobile-app/src/styles/styles.scss"],
            "scripts": []
          },
          "configurations": {
            "production": {
              "fileReplacements": [
                {
                  "replace": "apps/mobile-app/src/environments/environment.ts",
                  "with": "apps/mobile-app/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": "@angular-devkit/build-angular:dev-server",
          "options": {
            "port": 3000,
            "browserTarget": "mobile-app:build"
          },
          "configurations": {
            "production": {
              "browserTarget": "mobile-app:build:production"
            }
          }
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "mobile-app:build"
          }
        },
        "test": {
          "builder": "@angular-devkit/build-angular:karma",
          "options": {
            "main": "apps/mobile-app/src/test.ts",
            "polyfills": "apps/mobile-app/src/polyfills.ts",
            "tsConfig": "apps/mobile-app/tsconfig.spec.json",
            "karmaConfig": "apps/mobile-app/karma.conf.js",
            "styles": ["apps/mobile-app/src/styles/styles.scss"],
            "scripts": [],
            "assets": [
              "apps/mobile-app/src/favicon.ico",
              "apps/mobile-app/src/assets"
            ]
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": [
              "apps/mobile-app/tsconfig.app.json",
              "apps/mobile-app/tsconfig.spec.json"
            ],
            "exclude": ["**/node_modules/**"]
          }
        },
        "ionic-cordova-build": {
          "builder": "@ionic/angular-toolkit:cordova-build",
          "options": {
            "browserTarget": "mobile-app:build"
          },
          "configurations": {
            "production": {
              "browserTarget": "mobile-app:build:production"
            }
          }
        },
        "ionic-cordova-serve": {
          "builder": "@ionic/angular-toolkit:cordova-serve",
          "options": {
            "cordovaBuildTarget": "app:ionic-cordova-build",
            "devServerTarget": "mobile-app:serve"
          },
          "configurations": {
            "production": {
              "cordovaBuildTarget": "app:ionic-cordova-build:production",
              "devServerTarget": "mobile-app:serve:production"
            }
          }
        }
      }
    },
    "mobile-app-e2e": {
      "root": "apps/mobile-app-e2e",
      "projectType": "application",
      "prefix": "",
      "architect": {
        "e2e": {
          "builder": "@angular-devkit/build-angular:protractor",
          "options": {
            "protractorConfig": "apps/mobile-app-e2e/protractor.conf.js",
            "devServerTarget": "mobile-app:serve"
          },
          "configurations": {
            "production": {
              "devServerTarget": "mobile-app:serve:production"
            }
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": "apps/mobile-app-e2e/tsconfig.e2e.json",
            "exclude": ["**/node_modules/**"]
          }
        }
      }
    }
  },
  "cli": {
    "warnings": {
      "typescriptMismatch": false,
      "versionMismatch": false
    },
    "defaultCollection": "@nrwl/schematics",
    "packageManager": "npm"
  },
  "schematics": {
    "@nrwl/schematics:application": {
      "style": "scss"
    },
    "@nrwl/schematics:library": {
      "style": "scss"
    }
  },
  "defaultProject": "mobile-app"
}
elliotmendiola commented 5 years ago

Figured out the problem(s)

Typescript version 3.1.3 breaks ng g when using nx ng g app [appName] fails with no message (but it does error, confirmed in console, short circuits &&) ng g lib [libName] fails with a message seemingly related to parsing json (may depend on my other packages)

Also tsconfig can cause failures ng g lib [libName] would fail with the message Cannot convert undefined or null to object

In order to fix this issue, make sure you have a paths property in your tsconfig.json compilerOptions

    "paths": {},
macjohnny commented 5 years ago

when creating a new project with the latest versions @angular/cli@7.3.0 and @nrwl/nx@7.5.1, running ng generate lib myLib works as expected.

vsavkin commented 5 years ago

Closing this issue. If you can still repro the issue with Nx 7.8, could you reopen it with a repro?

github-actions[bot] commented 1 year ago

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.