Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate fails when there is a lint target without eslintConfig option at a root project.json #18544

Closed
mpsanchis opened this issue Aug 9, 2023 · 1 comment · Fixed by #18762
Assignees
Labels
outdated scope: linter Issues related to Eslint support in Nx type: bug

Comments

@mpsanchis
Copy link
Contributor

mpsanchis commented Aug 9, 2023

Current Behavior

When creating a new NX plugin, if the project.json at the root of the repository contains a lint target that doesn't contain the option eslintConfig, and there is no .eslintrc.base.json at the root, then generation of a new plugin fails.

In other words, running:

nx g plugin my-plugin --directory=plugins --importPath=@myorg/my-plugin

Leads to an error (see failure logs below).

When looking at the code (function findLintTarget), I saw that NX is looking for targets called lint or targets with executor @nx/linter:eslint. This breaks the assumption that we can call targets however we want, and add whatever executors we want to them.

Expected Behavior

Running the nx g plugin my-plugin ... command simply generates a new NX plugin without checking so many details about the structure of my repo.

I unfortunately don't know the NX codebase well enough to suggest a change, but I would avoid mixing migration with plugin generation. They seem two very different topics from a high level perspective.

GitHub Repo

No response

Steps to Reproduce

  1. Create an NX project with a project.json at the root
  2. Add a toy-example lint target to it, such as: "lint": { "executor": "nx:noop" }
  3. Make sure there is no .eslintrc.base.json at root level
  4. Generate a plugin with nx g @nx/plugin:plugin my-plugin

Nx Report

Node   : 18.16.1
   OS     : darwin-arm64
   yarn   : 1.22.19
   
   nx                 : 16.6.0
   @nx/js             : 16.6.0
   @nx/jest           : 16.6.0
   @nx/linter         : 16.6.0
   @nx/workspace      : 16.6.0
   @nx/devkit         : 16.6.0
   @nx/eslint-plugin  : 16.6.0
   @nx/plugin         : 16.6.0
   @nx/react          : 16.6.0
   @nrwl/tao          : 16.6.0
   @nx/vite           : 16.6.0
   @nx/web            : 16.6.0
   typescript         : 5.1.3
   ---------------------------------------
   Community plugins:
   @jnxplus/nx-boot-maven : 7.3.0
   @jscutlery/semver      : 3.0.0
   @nx-tools/nx-container : 5.0.2
   ngx-deploy-npm         : 5.2.0

[...]

Failure Logs

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


TypeError: Cannot read properties of undefined (reading 'eslintConfig')
    at /my/repo/path/node_modules/@nx/linter/src/generators/init/init-migration.js:14:104
    at Array.forEach (<anonymous>)
    at migrateConfigToMonorepoStyle (/my/repo/path/node_modules/@nx/linter/src/generators/init/init-migration.js:11:14)
    at /my/repo/path/node_modules/@nx/linter/src/generators/lint-project/lint-project.js:50:67
    at Generator.next (<anonymous>)
    at /my/repo/path/node_modules/@nx/linter/node_modules/tslib/tslib.js:169:75
    at new Promise (<anonymous>)
    at Object.__awaiter (/my/repo/path/node_modules/@nx/linter/node_modules/tslib/tslib.js:165:16)
    at lintProjectGenerator (/my/repo/path/node_modules/@nx/linter/src/generators/lint-project/lint-project.js:17:20)
    at /my/repo/path/node_modules/@nx/js/src/generators/library/library.js:154:22


### Operating System

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

### Additional Information

For those looking for a quick fix, having a `.eslintrc.base.json` at the root solves the issue.
@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 29, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated scope: linter Issues related to Eslint support in Nx type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants