nrwl / nx

Smart Monorepos ยท Fast CI
https://nx.dev
MIT License
23.65k stars 2.36k forks source link

Eslint failed with Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory #4743

Closed Lonli-Lokli closed 3 years ago

Lonli-Lokli commented 3 years ago

Current Behavior

eslint --quiet fails with current structure with Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory

Expected Behavior

No errors

Steps to Reproduce

Just migrated from v10 to v11, might be caused by wrong ts configuration (no include in tsconfig), see https://github.com/typescript-eslint/typescript-eslint/issues/1551

Environment

Node : 10.22.0 OS : win32 x64 npm : 6.14.6

nx : Not Found @nrwl/angular : 11.2.10 @nrwl/cli : 11.2.10 @nrwl/cypress : 11.2.10 @nrwl/devkit : 11.2.10 @nrwl/eslint-plugin-nx : 11.2.10 @nrwl/express : Not Found @nrwl/jest : 11.2.10 @nrwl/linter : 11.2.10 @nrwl/nest : Not Found @nrwl/next : Not Found @nrwl/node : Not Found @nrwl/react : Not Found @nrwl/schematics : Not Found @nrwl/tao : 11.2.10 @nrwl/web : Not Found @nrwl/workspace : 11.2.10 typescript : 4.0.3

IsaacConDosA commented 3 years ago

Same issue here! :(

JamesHenry commented 3 years ago

@Lonli-Lokli Please provide something closer to a reproduction of the issue.

If you ran eslint --quiet then you are not using the Nx tooling to invoke ESLint.

In order to begin looking into this we need much more information about your setup: configuration files, the commands you ran.

I also strongly advise checking out the docs on typescript-eslint regarding performance so that you can understand what is going on: https://github.com/typescript-eslint/typescript-eslint/blob/master/docs/getting-started/linting/FAQ.md#my-linting-feels-really-slow

Lonli-Lokli commented 3 years ago

@JamesHenry Ok we use husky + lint-staged + prettier + eslint in our project.

So on every commit we run linting to ensure everything is ok. We cannot run angular nx lint directly as it does not work with lint-staged, eg it can lint only staged files.

So we have this in our package.json

  "husky": {
    "hooks": {
      "pre-commit": "lint-staged"
    }
  },
  "lint-staged": {
    "*.ts": [
      "import-conductor --staged -p @test -i libs/api/src/generated/**/*.ts",
      "prettier --write",
      "node --max_old_space_size=4096 node_modules/eslint/bin/eslint.js --quiet"
    ],
    "*.{js,json,md,html}": [
      "prettier --write"
    ],
    "*.{scss,css}": [
      "prettier --write",
      "stylelint --syntax scss --fix"
    ]
  },
willyboy commented 3 years ago

I'm seeing this with nx/ng lint for a newly generated Nest app which seems to have added eslint (on v10 though)

github-actions[bot] commented 3 years ago

This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs. If we missed this issue please reply to keep it active. Thanks for being a part of the Nx community! ๐Ÿ™

Lonli-Lokli commented 3 years ago

@JamesHenry was my answer clear for you?

github-actions[bot] commented 3 years ago

This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs. If we missed this issue please reply to keep it active. Thanks for being a part of the Nx community! ๐Ÿ™

JamesHenry commented 3 years ago

@Lonli-Lokli To make that setup work, you will need to have a dedicated eslint-focused tsconfig which includes all of your TypeScript files. The way typescript + eslint is configured with Nx is focused on using typescript + eslint with Nx, specifically - meaning on a project by project basis.

You will also need to set the parserOptions.project value to use that dedicated eslint config, instead of the standard root Nx one, just for this use case. I'm not sure if overriding one subsection of a config like parserOptions.project is actually possible via the eslint CLI, so you may additionally have to create a dedicated eslint config file for this.

Putting it all together - NOTE: untested, and off the top of my head, so may need some tweaking:

tsconfig.eslint.json

{
  "extends": "./tsconfig.base.json",
  "includes": ["**/*.ts"]
}

lint-staged.eslintrc.json

{
  "extends": "./.eslintrc.json",
  "overrides": [
    {
      "files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
      "parserOptions": {
        "project": ["./tsconfig.eslint.json"]
      }
    }
  ]
}

Then update your call to the ESLint CLI (seemingly "node --max_old_space_size=4096 node_modules/eslint/bin/eslint.js --quiet") to point specifically at the lint-staged.eslintrc.json, or whatever name you go with.

Hope that helps!

Lonli-Lokli commented 3 years ago

@JamesHenry thanks I will give it a try.

Have you considered husky & lint-staged integration in Nrwl apps?

github-actions[bot] commented 3 years ago

This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs. If we missed this issue please reply to keep it active. Thanks for being a part of the Nx community! ๐Ÿ™

meeroslav commented 3 years ago

@Lonli-Lokli we will not integrate husky in the generated workspace, as that would interfere with existing setup people already have. Additionally, pre-commit hooks rarely run just linter, so it's hard to build a silver bullet that would fit everyone's needs.

We do however use husky internally on the nx where we run certain checks on pre-push.

We might integrate lint-staged at some point, but currently it's not so trivial.

JamesHenry commented 3 years ago

@Lonli-Lokli @meeroslav I discussed this with Victor yesterday.

As meeroslav says, we do not have any plans to integrate that tooling into Nx, but we are working on the linting performance on two different fronts concurrently:

Those, combined with the more informal tips I gave above around a solution above for your specific scenario should covers things well for now and as per Victor's instructions I will be closing this one.

Markus-Ende commented 2 years ago

@Lonli-Lokli To make that setup work, you will need to have a dedicated eslint-focused tsconfig which includes all of your TypeScript files. The way typescript + eslint is configured with Nx is focused on using typescript + eslint with Nx, specifically - meaning on a project by project basis.

You will also need to set the parserOptions.project value to use that dedicated eslint config, instead of the standard root Nx one, just for this use case. I'm not sure if overriding one subsection of a config like parserOptions.project is actually possible via the eslint CLI, so you may additionally have to create a dedicated eslint config file for this.

Putting it all together - NOTE: untested, and off the top of my head, so may need some tweaking:

tsconfig.eslint.json

{
  "extends": "./tsconfig.base.json",
  "includes": ["**/*.ts"]
}

lint-staged.eslintrc.json

{
  "extends": "./.eslintrc.json",
  "overrides": [
    {
      "files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
      "parserOptions": {
        "project": ["./tsconfig.eslint.json"]
      }
    }
  ]
}

Then update your call to the ESLint CLI (seemingly "node --max_old_space_size=4096 node_modules/eslint/bin/eslint.js --quiet") to point specifically at the lint-staged.eslintrc.json, or whatever name you go with.

Hope that helps!

A bit late but wanted to share, that this setup worked for me!

Just had to remove the *.js files from the new lint-staged.eslintrc.json and add --no-ignore, otherwise the ignore pattern of root .eslintrc.json kicks in:

lint-staged.eslintrc.json

 {
   "extends": "./.eslintrc.json",
   "overrides": [
     {
       "files": ["*.ts", "*.tsx"],
       "parserOptions": {
         "project": ["./tsconfig.eslint.json"]
       }
     }
   ]
 }

.lintstagedrc.js

module.exports = {
 // ...
  '*.{js,ts,html}': (files) => [
    `eslint --quiet --no-ignore -c lint-staged.eslintrc.json ${files.join(
      ' '
    )}`,
  ],
};
github-actions[bot] commented 1 year 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.