nrwl / nx

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

nx 19.6.3 cannot generate plugins TypeError: Cannot read properties of undefined (reading 'length') #27662

Closed noelsoong closed 2 months ago

noelsoong commented 2 months ago

Current Behavior

Using this command

pnpm nx g @nx/plugin:plugin generate-fastify-lib  --directory=tools/generate-fastify-lib --verbose

After selecting As provided i get an error: TypeError: Cannot read properties of undefined (reading 'length')

Expected Behavior

Generate a nx plugin for a generator and associated files

GitHub Repo

No response

Steps to Reproduce

  1. follow this tutorial https://nx.dev/extending-nx/recipes/local-generators

Nx Report

Node           : 18.18.2
OS             : darwin-arm64
Native Target  : aarch64-macos
pnpm           : 9.9.0

nx                 : 19.6.3
@nx/js             : 19.6.3
@nx/jest           : 19.6.3
@nx/linter         : 19.6.3
@nx/eslint         : 19.6.3
@nx/workspace      : 19.6.3
@nx/devkit         : 19.6.3
@nx/esbuild        : 19.6.3
@nx/eslint-plugin  : 19.6.3
@nx/node           : 19.6.3
@nx/plugin         : 19.6.3
@nrwl/tao          : 19.6.3
@nx/vite           : 19.6.3
@nx/web            : 19.6.3
typescript         : 5.5.4
---------------------------------------
Registered Plugins:
@nx/eslint/plugin
@nx/vite/plugin

Failure Logs

TypeError: Cannot read properties of undefined (reading 'length')
    at addBlockToFlatConfigExport (/Users/noelsoong/Workspace/iticket-stack/node_modules/.pnpm/@nx+eslint@19.6.3_@babel+traverse@7.25.4_@swc-node+register@1.10.9_@swc+core@1.7.18_@swc+help_ofigtkzqr2ojnu4zu7n5hh2eca/node_modules/@nx/eslint/src/generators/utils/flat-config/ast-utils.js:259:36)
    at addOverrideToLintConfig (/Users/noelsoong/Workspace/iticket-stack/node_modules/.pnpm/@nx+eslint@19.6.3_@babel+traverse@7.25.4_@swc-node+register@1.10.9_@swc+core@1.7.18_@swc+help_ofigtkzqr2ojnu4zu7n5hh2eca/node_modules/@nx/eslint/src/generators/utils/eslint-file.js:120:73)
    at updateRootEslintConfig (/Users/noelsoong/Workspace/iticket-stack/node_modules/.pnpm/@nx+plugin@19.6.3_@babel+traverse@7.25.4_@swc-node+register@1.10.9_@swc+core@1.7.18_@swc+help_y5nd52qfgcia5zpht5srvc7s2a/node_modules/@nx/plugin/src/generators/lint-checks/generator.js:146:55)
    at pluginLintCheckGenerator (/Users/noelsoong/Workspace/iticket-stack/node_modules/.pnpm/@nx+plugin@19.6.3_@babel+traverse@7.25.4_@swc-node+register@1.10.9_@swc+core@1.7.18_@swc+help_y5nd52qfgcia5zpht5srvc7s2a/node_modules/@nx/plugin/src/generators/lint-checks/generator.js:16:9)
    at pluginGeneratorInternal (/Users/noelsoong/Workspace/iticket-stack/node_modules/.pnpm/@nx+plugin@19.6.3_@babel+traverse@7.25.4_@swc-node+register@1.10.9_@swc+core@1.7.18_@swc+help_y5nd52qfgcia5zpht5srvc7s2a/node_modules/@nx/plugin/src/generators/plugin/plugin.js:102:39)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async /Users/noelsoong/Workspace/iticket-stack/node_modules/.pnpm/nx@19.6.3_@swc-node+register@1.10.9_@swc+core@1.7.18_@swc+helpers@0.5.12__@swc+types@0.1.12_t_rejoiars5jmne3qwvjpmskeevu/node_modules/nx/src/command-line/generate/generate.js:237:26
    at async handleErrors (/Users/noelsoong/Workspace/iticket-stack/node_modules/.pnpm/nx@19.6.3_@swc-node+register@1.10.9_@swc+core@1.7.18_@swc+helpers@0.5.12__@swc+types@0.1.12_t_rejoiars5jmne3qwvjpmskeevu/node_modules/nx/src/utils/params.js:22:24)
    at async Object.handler (/Users/noelsoong/Workspace/iticket-stack/node_modules/.pnpm/nx@19.6.3_@swc-node+register@1.10.9_@swc+core@1.7.18_@swc+helpers@0.5.12__@swc+types@0.1.12_t_rejoiars5jmne3qwvjpmskeevu/node_modules/nx/src/command-line/generate/command-object.js:14:22)


### Package Manager Version

_No response_

### Operating System

- [X] macOS
- [ ] Linux
- [ ] Windows
- [ ] Other (Please specify)

### Additional Information

_No response_
noelsoong commented 2 months ago

Found out that eslintrc plugin does not support esm modules so i will try converting my eslint.config.js to eslint.config.cjs

noelsoong commented 2 months ago

converted to eslint.config.cjs and now running into this error

TypeError: Cannot read properties of null (reading 'length')
    at createSourceFile2 (/Users/noelsoong/Workspace/iticket-stack/node_modules/.pnpm/typescript@5.4.5/node_modules/typescript/lib/typescript.js:29629:58)
    at parseSourceFileWorker (/Users/noelsoong/Workspace/iticket-stack/node_modules/.pnpm/typescript@5.4.5/node_modules/typescript/lib/typescript.js:29502:30)
    at Object.parseSourceFile (/Users/noelsoong/Workspace/iticket-stack/node_modules/.pnpm/typescript@5.4.5/node_modules/typescript/lib/typescript.js:29326:26)
    at Object.createSourceFile (/Users/noelsoong/Workspace/iticket-stack/node_modules/.pnpm/typescript@5.4.5/node_modules/typescript/lib/typescript.js:28492:23)
    at hasOverride (/Users/noelsoong/Workspace/iticket-stack/node_modules/.pnpm/@nx+eslint@19.6.3_@babel+traverse@7.25.4_@swc-node+register@1.10.9_@swc+core@1.7.18_@swc+help_wqxk2dyc3ojsa2rzxwmg4k5uhm/node_modules/@nx/eslint/src/generators/utils/flat-config/ast-utils.js:71:23)
    at lintConfigHasOverride (/Users/noelsoong/Workspace/iticket-stack/node_modules/.pnpm/@nx+eslint@19.6.3_@babel+traverse@7.25.4_@swc-node+register@1.10.9_@swc+core@1.7.18_@swc+help_wqxk2dyc3ojsa2rzxwmg4k5uhm/node_modules/@nx/eslint/src/generators/utils/eslint-file.js:178:44)
    at updateProjectEslintConfig (/Users/noelsoong/Workspace/iticket-stack/node_modules/.pnpm/@nx+plugin@19.6.3_@babel+traverse@7.25.4_@swc-node+register@1.10.9_@swc+core@1.7.18_@swc+help_qgvghtnpg6cztnx32rcihugbzq/node_modules/@nx/plugin/src/generators/lint-checks/generator.js:109:53)
    at pluginLintCheckGenerator (/Users/noelsoong/Workspace/iticket-stack/node_modules/.pnpm/@nx+plugin@19.6.3_@babel+traverse@7.25.4_@swc-node+register@1.10.9_@swc+core@1.7.18_@swc+help_qgvghtnpg6cztnx32rcihugbzq/node_modules/@nx/plugin/src/generators/lint-checks/generator.js:17:9)
    at pluginGeneratorInternal (/Users/noelsoong/Workspace/iticket-stack/node_modules/.pnpm/@nx+plugin@19.6.3_@babel+traverse@7.25.4_@swc-node+register@1.10.9_@swc+core@1.7.18_@swc+help_qgvghtnpg6cztnx32rcihugbzq/node_modules/@nx/plugin/src/generators/plugin/plugin.js:102:39)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

nx report now looks like this

Node           : 20.11.1
OS             : darwin-arm64
Native Target  : aarch64-macos
pnpm           : 9.9.0

nx                 : 19.6.3
@nx/js             : 19.6.3
@nx/jest           : 19.6.3
@nx/linter         : 19.6.3
@nx/eslint         : 19.6.3
@nx/workspace      : 19.6.3
@nx/devkit         : 19.6.3
@nx/esbuild        : 19.6.3
@nx/eslint-plugin  : 19.6.3
@nx/node           : 19.6.3
@nx/plugin         : 19.6.3
@nrwl/tao          : 19.6.3
@nx/vite           : 19.6.3
@nx/web            : 19.6.3
typescript         : 5.4.5
---------------------------------------
Registered Plugins:
@nx/eslint/plugin
@nx/vite/plugin

package.json

{
  "name": "@iticketnz/root",
  "license": "MIT",
  "type": "module",
  "packageManager": "pnpm@9.9.0+sha512.60c18acd138bff695d339be6ad13f7e936eea6745660d4cc4a776d5247c540d0edee1a563695c183a66eb917ef88f2b4feb1fc25f32a7adcadc7aaf3438e99c1",
  "scripts": {
    "build:admin-api": "pnpm nx build admin-api",
    "serve:admin-api": "pnpm nx serve --project=admin-api",
    "build": "pnpm nx run-many --target=build --all",
    "test:unit": "pnpm nx run-many --target=test:unit --all",
    "start": "pnpm nx serve",
    "publish:pnpm": "pnpm publish -r",
    "publish": "nx run-many --target=publish --all",
    "compile": "tsc --project tsconfig.json ",
    "lint": "pnpm nx run-many --target=lint --all ",
    "check:types": "nx run-many --target=check:types --all",
    "clean": "rm -rf dist"
  },
  "private": true,
  "devDependencies": {
    "@eslint/eslintrc": "^3.1.0",
    "@eslint/js": "~9.9.1",
    "@fastify/autoload": "^5.8.0",
    "@fastify/sensible": "~5.6.0",
    "@fastify/swagger": "^8.14.0",
    "@fastify/swagger-ui": "^3.0.0",
    "@fastify/type-provider-typebox": "^4.0.0",
    "@iticketnz/core": "workspace:^",
    "@iticketnz/eslint-config": "workspace:^",
    "@iticketnz/models": "workspace:^",
    "@iticketnz/organisations": "workspace:^",
    "@iticketnz/prettier-config": "workspace:^",
    "@iticketnz/users": "workspace:^",
    "@nx/esbuild": "19.6.3",
    "@nx/eslint": "19.6.3",
    "@nx/eslint-plugin": "19.6.3",
    "@nx/jest": "19.6.3",
    "@nx/js": "19.6.3",
    "@nx/node": "19.6.3",
    "@nx/plugin": "19.6.3",
    "@nx/vite": "19.6.3",
    "@nx/web": "19.6.3",
    "@nx/workspace": "19.6.3",
    "@sinclair/typebox": "^0.28.15",
    "@supabase/supabase-js": "^2.45.1",
    "@swc-node/register": "~1.10.9",
    "@swc/core": "~1.7.18",
    "@swc/helpers": "~0.5.12",
    "@types/eslint__js": "^8.42.3",
    "@types/jest": "^29.5.12",
    "@types/node": "~20.12.7",
    "@typescript-eslint/eslint-plugin": "7.8.0",
    "@typescript-eslint/parser": "7.8.0",
    "@vitest/coverage-v8": "^1.5.2",
    "@vitest/ui": "^1.5.2",
    "ajv": "^8.12.0",
    "applicationinsights": "^3.0.1",
    "axios": "^1.6.0",
    "connection-string": "^4.4.0",
    "copyfiles": "^2.4.1",
    "dotenv": "^16.4.5",
    "esbuild": "^0.23.1",
    "esbuild-plugin-tsc": "^0.4.0",
    "eslint": "~9.9.1",
    "eslint-config-prettier": "^9.1.0",
    "fastify": "~4.26.2",
    "fastify-plugin": "~4.5.0",
    "fluent-json-schema": "^4.2.1",
    "globals": "^15.0.0",
    "jest": "^29.7.0",
    "jest-environment-node": "^29.4.1",
    "jose": "^5.2.2",
    "jsonc-eslint-parser": "^2.4.0",
    "knex": "^3.1.0",
    "knex-paginate": "^3.1.2",
    "libphonenumber-js": "^1.10.45",
    "prettier": "^3.2.5",
    "ts-jest": "^29.1.2",
    "ts-node": "10.9.2",
    "tsconfig-paths": "^4.2.0",
    "tslib": "^2.7.0",
    "typescript": "~5.4.2",
    "vite": "~5.2.10",
    "vite-tsconfig-paths": "^4.3.2",
    "vitest": "^1.5.2"
  },
  "dependencies": {
    "nx": "19.6.3"
  }
}
noelsoong commented 2 months ago

tried nx reset deleting node_modules and pnpm-lock.yaml then reinstalling using pnpm i typescript version still goes to 5.4.5 instead of 5.4.2

noelsoong commented 2 months ago

I fixed it by reverting back to nx version 18.3.4 and converting all the eslint files to .cjs files and converted module imports to common js require and module.exports.

github-actions[bot] commented 1 month 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.