simondotm / nx-firebase

Firebase plugin for Nx Monorepos
https://www.npmjs.com/package/@simondotm/nx-firebase
MIT License
175 stars 31 forks source link

Error initializing a new app from a fresh nx workspace #104

Closed bhaskarmurthy closed 1 year ago

bhaskarmurthy commented 1 year ago

I'm trying to add nx-firebase to a freshly created nx workspace.

npx nx g @simondotm/nx-firebase:app --verbose

>  NX  Generating @simondotm/nx-firebase:application

✔ What name would you like to use for the firebase node application? · platform

 >  NX   Cannot read properties of undefined (reading 'version')

TypeError: Cannot read properties of undefined (reading 'version')
    at addDependencies (/Users/bhaskar/Development/nx-workspace/vds/node_modules/@simondotm/nx-firebase/src/generators/init/lib/add-dependencies.js:46:77)
    at /Users/bhaskar/Development/nx-workspace/vds/node_modules/@simondotm/nx-firebase/src/generators/init/init.js:26:63
    at Generator.next (<anonymous>)
    at fulfilled (/Users/bhaskar/Development/nx-workspace/vds/node_modules/tslib/tslib.js:164:62)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

For some reason looks like workspaceNxVersion is undefined in the init generator:

    addDevDependencyIfNotPresent('@nrwl/devkit', utils_1.workspaceNxVersion.version);

My nx config is:

 >  NX   Report complete - copy this into the issue template

   Node : 18.14.0
   OS   : darwin arm64
   npm  : 9.3.1

   nx                      : 15.7.0
   @nrwl/jest              : 15.7.0
   @nrwl/linter            : 15.7.0
   @nrwl/workspace         : 15.7.0
   @nrwl/cli               : 15.7.0
   @nrwl/devkit            : 15.7.0
   @nrwl/eslint-plugin-nx  : 15.7.0
   @nrwl/js                : 15.7.0
   @nrwl/node              : 15.7.0
   @nrwl/tao               : 15.7.0
   @nrwl/webpack           : 15.7.0
   typescript              : 4.8.4
   ---------------------------------------
   Community plugins:
   @simondotm/nx-firebase : 1.0.0
simondotm commented 1 year ago

that's odd, and hasn't shown up in any e2e tests - maybe a 15.7.0 change 🤔 thanks for reporting I'll look into it

simondotm commented 1 year ago

@bhaskarmurthy - please could you let me know if nx is in your package.json as a dependency or a devDependencies ? I suspect the former. I will make that code more robust regardless.

bhaskarmurthy commented 1 year ago

good q - i'm using npx nx, and don't have nx in my package.json or installed globally

simondotm commented 1 year ago

thats quite unusual. scaffolding a basic Nx workspace with npx create-nx-workspace at a minimum generates a package.json with nx in devDependencies 🤔

{
  "name": "simontest",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {},
  "private": true,
  "dependencies": {},
  "devDependencies": {
    "@nrwl/js": "15.3.0",
    "@nrwl/workspace": "15.3.0",
    "nx": "15.3.0",
    "prettier": "^2.6.2",
    "typescript": "~4.8.2"
  }
}
bhaskarmurthy commented 1 year ago

Very strange.

My list of deps is definitely missing nx:

{
  "name": "my-workspace",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {},
  "private": true,
  "devDependencies": {
    "@nrwl/cli": "15.7.0",
    "@nrwl/devkit": "15.7.0",
    "@nrwl/eslint-plugin-nx": "15.7.0",
    "@nrwl/jest": "15.7.0",
    "@nrwl/js": "15.7.0",
    "@nrwl/linter": "15.7.0",
    "@nrwl/node": "15.7.0",
    "@nrwl/tao": "15.7.0",
    "@nrwl/workspace": "15.7.0",
    "@types/jest": "28.1.1",
    "@types/node": "16.11.7",
    "@typescript-eslint/eslint-plugin": "^5.36.1",
    "@typescript-eslint/parser": "^5.36.1",
    "eslint": "~8.15.0",
    "eslint-config-prettier": "8.1.0",
    "jest": "28.1.1",
    "jest-environment-jsdom": "28.1.1",
    "prettier": "2.8.4",
    "ts-jest": "28.0.5",
    "ts-node": "10.9.1",
    "typescript": "4.8.4"
  },
  "dependencies": {
    "tslib": "^2.3.0"
  }
}
bhaskarmurthy commented 1 year ago

Just ran the init command in a new workspace, this is the output:

I used the ts [an empty workspace with the JS/TS plugin preinstalled] choice

{
  "name": "workspace",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {},
  "private": true,
  "dependencies": {},
  "devDependencies": {
    "@nrwl/cli": "13.7.3",
    "@nrwl/js": "13.7.3",
    "@nrwl/tao": "13.7.3",
    "@nrwl/workspace": "13.7.3",
    "@types/node": "16.11.7",
    "prettier": "^2.5.1",
    "typescript": "~4.5.2"
  }
}
bhaskarmurthy commented 1 year ago

Okay - so looks like my npx is bringing in nx 13.x -> while the latest is 15.x, and has a different structure that looks like the one you shared.

I ended up re-creating my workspace with nx@latest and now have the nx dependency.

bhaskarmurthy commented 1 year ago

Thanks for the quick response and assistance @simondotm!

simondotm commented 1 year ago

Ok yeah, nx is the new CLI package as of 13.9.7. The plugin is built against 13.10.6 minimum so that would explain it.

Lowell20 commented 1 year ago

will this work with nx 15? or is there a roadmap to support this?

simondotm commented 1 year ago

will this work with nx 15? or is there a roadmap to support this?

Yes as far as I know the plugin is compatible with v15.x

Lowell20 commented 1 year ago

I think I'm getting an error because I now don't have an angular.json file. But I will try again. I'm setting up for the first time.