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 app does not have .eslintrc.json #18377

Closed
1 of 4 tasks
jaredzwick opened this issue Jul 29, 2023 · 3 comments · Fixed by #18762
Closed
1 of 4 tasks

Generate fails when app does not have .eslintrc.json #18377

jaredzwick opened this issue Jul 29, 2023 · 3 comments · Fixed by #18762
Assignees
Labels
outdated scope: linter Issues related to Eslint support in Nx scope: react Issues related to React support for Nx type: bug

Comments

@jaredzwick
Copy link

Current Behavior

Generating a new library using @nx/react within a workspace that has an app of nx/go backend and an app of nx/react frontend.

Generating a new nx react lib fails with
TypeError: Cannot read properties of undefined (reading 'eslintConfig')

Comes from this function in @nx/linter/src/generators/init/init-migration.js

function migrateConfigToMonorepoStyle(projects, tree, unitTestRunner) {
    (0, devkit_1.writeJson)(tree, '.eslintrc.base.json', (0, global_eslint_config_1.getGlobalEsLintConfiguration)(unitTestRunner));
    // update extens in all projects' eslint configs
    console.log("HERE PROJECT", JSON.stringify(projects))
    projects.forEach((project) => {
        const lintTarget = findLintTarget(project);
        if (lintTarget) {
            console.log("HERE", JSON.stringify(lintTarget))
                const projectEslintPath = (0, devkit_1.joinPathFragments)(project.root, **lintTarget.options.eslintConfig** || (0, eslint_file_1.findEslintFile)(tree, project.root));
                migrateEslintFile(projectEslintPath, tree);
}});}

able to solve by adding a .eslintrc.json file into apps/backend directory; however I think there should be some sort of check here as not all project's contain eslint if considering managing multiple languages in a monorepo.

Expected Behavior

Should generate the react lib without regard to whether go has a lint config

GitHub Repo

No response

Steps to Reproduce

  1. Generate a @nx/react frontend app
  2. Generate a @nx/go backend app
  3. Attempt to generate a @nx/react lib

Nx Report

>  NX   Report complete - copy this into the issue template

   Node   : 18.16.1
   OS     : linux-x64
   npm    : 9.5.1
   
   nx (global)        : 16.4.0
   nx                 : 16.5.5
   @nx/js             : 16.5.5
   @nx/linter         : 16.5.5
   @nx/workspace      : 16.5.5
   @nx/cypress        : 16.5.5
   @nx/devkit         : 16.5.5
   @nx/eslint-plugin  : 16.5.5
   @nx/react          : 16.5.5
   @nrwl/tao          : 16.5.5
   @nx/vite           : 16.5.5
   @nx/web            : 16.5.5
   typescript         : 5.1.6
   ---------------------------------------
   Community plugins:
   @nx-go/nx-go : 2.7.0

Failure Logs

HERE {"executor":"nx:run-commands","options":{"commands":["nx run-many -t lint --projects=frontend,pages,ui,store,backend,db,handler,router"]}}
HERE {"executor":"@nx-go/nx-go:lint"}

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


TypeError: Cannot read properties of undefined (reading 'eslintConfig')
    at /home/jared/pipes/node_modules/@nx/linter/src/generators/init/init-migration.js:16:108
    at Array.forEach (<anonymous>)
    at migrateConfigToMonorepoStyle (/home/jared/pipes/node_modules/@nx/linter/src/generators/init/init-migration.js:12:14)
    at /home/jared/pipes/node_modules/@nx/linter/src/generators/lint-project/lint-project.js:92:67
    at Generator.next (<anonymous>)
    at /home/jared/pipes/node_modules/tslib/tslib.js:169:75
    at new Promise (<anonymous>)
    at Object.__awaiter (/home/jared/pipes/node_modules/tslib/tslib.js:165:16)
    at lintProjectGenerator (/home/jared/pipes/node_modules/@nx/linter/src/generators/lint-project/lint-project.js:63:20)


    at /home/jared/pipes/node_modules/@nx/react/src/generators/library/lib/add-linting.js:13:70

Operating System

  • macOS
  • Linux
  • Windows
  • Other (Please specify)

Additional Information

No response

@mpsanchis
Copy link
Contributor

mpsanchis commented Aug 9, 2023

Hi team,

I have a running NX workspace since months, and today I ran across this issue when running the commands you suggest here:

nx g @nx/plugin:plugin my-plugin --verbose

and here:

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

Edit: added more information to my specific use case in a new issue
#18544

@AgentEnder AgentEnder added scope: react Issues related to React support for Nx scope: linter Issues related to Eslint support in Nx labels Aug 11, 2023
@meeroslav meeroslav self-assigned this Aug 21, 2023
@meeroslav
Copy link
Contributor

Thank you for report @mpsanchis. The fix is on the way

@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 scope: react Issues related to React support for Nx type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants