nrwl / nx

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

ES Lint not setup correctly on new project #28971

Open ccaspanello opened 1 day ago

ccaspanello commented 1 day ago

Current Behavior

When creating a new workspace ES Lint gives me errors. This occurs not only in Webstorm but also on the command line. I've tried this with a React project as well as a NestJS project. I'm not sure what is going on here. The following are steps to reproduce.

NX Version: v20.1.2

Error

nx lint my-app

> nx run my-app:lint

> eslint .

Oops! Something went wrong! :(

ESLint: 9.15.0

TypeError: Error while loading rule '@typescript-eslint/no-empty-function': Cannot read properties of undefined (reading 'allow')
Occurred while linting /Users/***/Desktop/nx-sandbox/apps/my-app/eslint.config.js
    at Object.create (/Users/***/Desktop/nx-sandbox/node_modules/.pnpm/eslint@9.15.0_jiti@1.21.6/node_modules/eslint/lib/rules/no-empty-function.js:125:18)

Expected Behavior

I would expect ES lint to work out of the box without further configuration

GitHub Repo

No response

Steps to Reproduce

  1. Create Workspace: npx create-nx-workspace --pm pnpm

  2. Follow the wizard:

    
    NX   Let's create a new workspace [https://nx.dev/getting-started/intro]

✔ Where would you like to create your workspace? · nx-sandbox ✔ Which stack do you want to use? · react ✔ What framework would you like to use? · none ✔ Integrated monorepo, or standalone project? · integrated ✔ Application name · my-app ✔ Which bundler would you like to use? · vite ✔ Test runner to use for end to end (E2E) tests · cypress ✔ Default stylesheet format · tailwind ✔ Which CI provider would you like to use? · github

NX Creating your v20.1.2 workspace.

✔ Installing dependencies with pnpm ✔ Successfully created the workspace: nx-sandbox. ✔ Nx Cloud has been set up successfully ✔ CI workflow has been generated successfully

NX Your CI setup is almost complete.


3. Go into workspace directory
`cd nx-sandbox`

4. Ensure dependencies are installed
`pnpm install`

5. Try to run the lint command
`nx lint my-app`

### Nx Report

```shell
NX   Report complete - copy this into the issue template

Node           : 22.3.0
OS             : darwin-arm64
Native Target  : aarch64-macos
pnpm           : 9.12.3

nx (global)        : 20.1.2
nx                 : 20.1.2
@nx/js             : 20.1.2
@nx/jest           : 20.1.2
@nx/eslint         : 20.1.2
@nx/workspace      : 20.1.2
@nx/cypress        : 20.1.2
@nx/eslint-plugin  : 20.1.2
@nx/react          : 20.1.2
@nx/vite           : 20.1.2
@nx/web            : 20.1.2
typescript         : 5.5.4
---------------------------------------
Registered Plugins:
@nx/vite/plugin
@nx/eslint/plugin
@nx/cypress/plugin
@nx/jest/plugin

Failure Logs

Package Manager Version

No response

Operating System

Additional Information

No response

bonejon commented 1 day ago

I've been struggling against this error, but have just found this issue. There seems to be an incompatibility / breaking change in eslint 9.15.

https://github.com/typescript-eslint/typescript-eslint/issues/10338

remove the ^ from the eslint entry in package.json to pin the version and it seems to work fine. "eslint": "9.14.0",

ccaspanello commented 1 day ago

@bonejon - Thanks for the advice. My current version was "eslint": "^9.8.0",. Removing the carrot did the trick. I guess when things like this happen (and they will) ... what is the right course of action and can/should NX do anything? I'm new to NX and I like it ... when it work ... when it doesn't it feels like it's hard to debug the "magic" it does.