ESLint Not Working with Ionic and Capacitor (Android/iOS) - JavaScript Heap Out of Memory

Discussão em 'Angular' iniciado por Vaibhav Shah, Abril 9, 2025.

  1. Vaibhav Shah

    Vaibhav Shah Guest

    I’m working on an Ionic Angular project with Capacitor, and I’m facing an issue where ESLint is not working properly. When I run eslint on my project, it fails with the following error:

    FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory


    I suspect the issue is related to how ESLint processes files in the android, ios, and www folders, as these directories contain a large number of files. When I deleted android, ios and www folder then npm run lint command executed successful.

    Here’s my setup:

    • Framework: Ionic Angular
    • Linting Setup: "eslint": "9.24.0",
    • Capacitor Version: 7.x
    • Node Version: 20.18.0


    What I’ve Tried

    1. Increasing Heap Memory:

    • Ran ESLint with more memory:(NODE_OPTIONS="--max_old_space_size=4096" eslint "src/**/*.{js,jsx,ts,tsx,html}" --fix)
    • Still getting the same error.

    2. Ignoring Large Directories:

    • Added the following to .eslintignore:
    android/ , ios/ , www/ , node_modules/


    My Package json file is

    {
    "name": "cj-web-portal",
    "version": "0.0.0",
    "scripts": {
    "ng": "ng",
    "start": "ng serve --port 4205",
    "build": "ng build",
    "build:dev": "node --max_old_space_size=5048 ./node_modules/@angular/cli/bin/ng build --configuration development --aot --output-hashing=all",
    "build:stag": "node --max_old_space_size=5048 ./node_modules/@angular/cli/bin/ng build --configuration staging --aot --output-hashing=all",
    "build:uat": "node --max_old_space_size=5048 ./node_modules/@angular/cli/bin/ng build --configuration uat --aot --output-hashing=all",
    "build:prod": "node --max_old_space_size=5048 ./node_modules/@angular/cli/bin/ng build --configuration production --aot --output-hashing=all",
    "watch": "ng build --watch --configuration development",
    "test": "ng test",
    "lint": "eslint \"src/**/*.{js,jsx,ts,tsx,html}\" --fix",
    "prepare": "husky",
    "pretty-quick": "pretty-quick --staged",
    "build:android": "ng build && npx cap copy android && npx cap open android",
    "build:ios": "ng build && npx cap copy ios && npx cap open ios"
    },
    "lint-staged": {
    "src/**/*.{js,jsx,ts,tsx,html}": "eslint --fix"
    },
    "private": true,
    "dependencies": {
    "@abacritt/angularx-social-login": "2.1.0",
    "@angular/animations": "^19.0.5",
    "@angular/cdk": "^19.2.7",
    "@angular/common": "^19.0.5",
    "@angular/compiler": "^19.0.5",
    "@angular/core": "^19.0.5",
    "@angular/forms": "^19.0.5",
    "@angular/platform-browser": "^19.0.5",
    "@angular/platform-browser-dynamic": "^19.0.5",
    "@angular/pwa": "^19.0.6",
    "@angular/router": "^19.0.5",
    "@angular/service-worker": "^19.0.6",
    "@capacitor/android": "^7.1.0",
    "@capacitor/app": "7.0.0",
    "@capacitor/barcode-scanner": "^2.0.3",
    "@capacitor/cli": "^7.1.0",
    "@capacitor/core": "7.2.0",
    "@capacitor/device": "^7.0.0",
    "@capacitor/haptics": "7.0.0",
    "@capacitor/ios": "^7.2.0",
    "@capacitor/keyboard": "7.0.0",
    "@capacitor/splash-screen": "^7.0.0",
    "@capacitor/status-bar": "^7.0.0",
    "@capawesome/capacitor-android-edge-to-edge-support": "^7.1.0",
    "@ionic/angular": "^8.5.2",
    "@ngx-translate/core": "^16.0.4",
    "@stripe/stripe-js": "~2.4.0",
    "bootstrap": "^5.3.2",
    "chart.js": "^4.4.3",
    "crypto-js": "^4.2.0",
    "date-fns": "^3.4.0",
    "dayjs": "^1.11.10",
    "jquery": "^3.7.1",
    "line-awesome": "^1.3.0",
    "ng-recaptcha": "^13.2.1",
    "ngx-color-picker": "^16.0.0",
    "ngx-daterangepicker-bootstrap": "^19.5.2",
    "ngx-drag-drop": "^17.0.0",
    "ngx-infinite-scroll": "^19.0.0",
    "ngx-monaco-editor-v2": "^18.1.0",
    "ngx-paypal": "^11.0.0",
    "ngx-scanner-qrcode": "1.6.9",
    "ngx-slick-carousel": "^19.0.0",
    "ngx-spinner": "^16.0.2",
    "ngx-stars": "^1.6.5",
    "ngx-stripe": "~17.0.0",
    "pkce-challenge": "^4.1.0",
    "primeng": "^17.10.0",
    "quill": "~1.3.7",
    "rxjs": "~7.8.0",
    "slick-carousel": "^1.8.1",
    "tslib": "^2.3.0",
    "zone.js": "~0.15.0"
    },
    "devDependencies": {
    "@angular-devkit/build-angular": "^19.0.6",
    "@angular-eslint/builder": "19.0.2",
    "@angular-eslint/eslint-plugin": "19.0.2",
    "@angular-eslint/eslint-plugin-template": "19.0.2",
    "@angular-eslint/schematics": "19.0.2",
    "@angular-eslint/template-parser": "19.0.2",
    "@angular/cli": "^19.0.6",
    "@angular/compiler-cli": "^19.0.5",
    "@capacitor/cli": "7.2.0",
    "@eslint/eslintrc": "3.3.1",
    "@eslint/js": "9.24.0",
    "@types/jasmine": "~5.1.0",
    "@typescript-eslint/eslint-plugin": "8.29.1",
    "@typescript-eslint/parser": "8.29.1",
    "eslint": "9.24.0",
    "husky": "9.1.7",
    "jasmine-core": "~5.1.0",
    "karma": "~6.4.0",
    "karma-chrome-launcher": "~3.2.0",
    "karma-coverage": "~2.2.0",
    "karma-jasmine": "~5.1.0",
    "karma-jasmine-html-reporter": "~2.1.0",
    "lint-staged": "15.5.0",
    "pretty-quick": "^4.0.0",
    "typescript": "~5.5.4"
    }
    }



    My eslint.config.mjs file is

    import { defineConfig, globalIgnores } from 'eslint/config';
    import path from 'node:path';
    import { fileURLToPath } from 'node:url';
    import js from '@eslint/js';
    import { FlatCompat } from '@eslint/eslintrc';

    const __filename = fileURLToPath(import.meta.url);
    const __dirname = path.dirname(__filename);
    const compat = new FlatCompat({
    baseDirectory: __dirname,
    recommendedConfig: js.configs.recommended,
    allConfig: js.configs.all,
    });

    export default defineConfig([
    globalIgnores([
    'projects/**/*',
    '**/package.json',
    '**/package-lock.json',
    '**/www',
    '**/ios',
    '**/android',
    'www/**/*',
    'ios/**/*',
    'android/**/*',
    '**/ionic.config.json',
    'e2e/**/*',
    '**/karma.conf.js',
    '**/commitlint.config.js',
    ]),
    {
    ignores: [
    'projects/**/*',
    '**/package.json',
    '**/package-lock.json',
    '**/www',
    '**/ios',
    '**/android',
    'www/**/*',
    'ios/**/*',
    'android/**/*',
    '**/ionic.config.json',
    'e2e/**/*',
    '**/karma.conf.js',
    '**/commitlint.config.js',
    ],
    },
    {
    files: ['**/*.ts'],

    extends: compat.extends('eslint:recommended', 'plugin:mad:angular-eslint/recommended', 'plugin:mad:angular-eslint/template/process-inline-templates'),

    languageOptions: {
    ecmaVersion: 5,
    sourceType: 'script',

    parserOptions: {
    project: ['tsconfig.json', 'e2e/tsconfig.json'],
    createDefaultProgram: true,
    },
    },

    rules: {
    '@angular-eslint/directive-selector': [
    'error',
    {
    type: 'attribute',
    prefix: 'app',
    style: 'camelCase',
    },
    ],

    eqeqeq: ['error', 'always'],
    semi: ['error', 'always'],
    '@angular-eslint/no-empty-lifecycle-method': 'off',
    '@angular-eslint/use-lifecycle-interface': 'off',
    '@angular-eslint/component-selector': 'off',
    'no-empty': 'off',
    'no-undef': 'off',
    'no-unused-vars': 'off',
    '@angular-eslint/prefer-standalone': 'off',
    },
    },
    {
    files: ['**/*.html'],

    extends: compat.extends('plugin:mad:angular-eslint/template/recommended', 'plugin:mad:angular-eslint/template/accessibility'),

    rules: {
    '@angular-eslint/template/label-has-associated-control': 'off',
    '@angular-eslint/template/elements-content': 'off',
    '@angular-eslint/template/click-events-have-key-events': 'off',
    '@angular-eslint/template/interactive-supports-focus': 'off',
    },
    },
    ]);

    Continue reading...

Compartilhe esta Página