'Extending tsconfig files not resolving the paths properly?

I am getting an issue with tsconfig after upgrading the package version.
Below is my folder structure (simplified, but keeping the actual hierarchy):
enter image description here

The tsconfig.json file inside activation folder extends the base.tsconfig.json like below:

{
    "extends": "../../base.tsconfig.json",
    "compilerOptions": {
        "baseUrl": "./",
    },
    "include": [
        "../../typings.d.ts",
        "src/**/*",
        "e2e/**/*",
        "integration/**/*"
    ]
}   

and my base.tsconfig.json looks like below:

{
    "compilerOptions": {
        "incremental": true,
        "target": "es2017",
        "module": "commonjs",
        "removeComments": true,
        "strict": true,
        "noImplicitAny": true,
        "strictNullChecks": true,
        "strictFunctionTypes": true,
        "strictBindCallApply": true,
        "strictPropertyInitialization": true,
        "noImplicitThis": true,
        "noUnusedLocals": false,
        "noUnusedParameters": true,
        "noImplicitReturns": true,
        "noFallthroughCasesInSwitch": true,
        "resolveJsonModule": true,
        "moduleResolution": "node",
        "baseUrl": "./",
        "allowSyntheticDefaultImports": true,
        "esModuleInterop": true,
        "experimentalDecorators": true,
        "emitDecoratorMetadata": true,
        "skipLibCheck": true,
        "forceConsistentCasingInFileNames": true,
        "paths": {
            "@security": ["../../services/security/src/modules/security"],
            "@security/*": ["../../services/security/src/modules/security/*"],
            "@nestjs": ["node_modules/@nestjs"],
            "@nestjs/*": ["node_modules/@nestjs/*"],
            "@nestjs/mongoose": ["node_modules/@nestjs/mongoose"],
            "@nestjs/mongoose/*": ["node_modules/@nestjs/mongoose/*"],
            "axios": ["node_modules/axios"],
            "axios/*": ["node_modules/axios/*"],
            "rxjs": ["node_modules/rxjs"],
            "rxjs/*": ["node_modules/rxjs/*"],
            "class-transformer": ["node_modules/class-transformer"],
            "class-transformer/*": ["node_modules/class-transformer/*"],
            // plus other path alias
        }
    }
}

Using my development IDEs (VS Code, WebStorm), I can navigate to the base.tsconfig.json file. However, when I run the tests for activation folder, I receive below error:
Parsing error: Cannot read file '/users/vanu.verma/projects/my-microservice/services/activation/base.tsconfig.json'

notice that services/activation is added to the path for base.tsconfig.json whereas it should not.

My package.json file for activation service:

{
    "name": "activation",
    "version": "0.0.1",
    "description": "Activation micro-service ",
    "license": "MIT",
    "scripts": {
        "prebuild": "rimraf dist",
        "build": "env NODE_ENV=production webpack",
        "format": "prettier --write \\\"src/**/*.ts\\\" \\\"e2e/**/*.ts\\\"",
        "start": "nest start",
        "start:dev": "env NODE_ENV=local ts-node-dev --respawn --watch .env,.env.local -r tsconfig-paths/register ./src/main.ts",
        "start:debug": "env NODE_ENV=local ts-node-dev --respawn --inspect=4321 --watch .env,.env.local -r tsconfig-paths/register ./src/main.ts",
        "start:prod": "node dist/main",
        "lint": "eslint -c .eslintrc.js --ext .ts .",
        "prettier": "prettier './**/*.ts' --write --list-different",
        "fixlint": "yarn lint --fix",
        "audit:deps": "/bin/bash -c 'yarn audit --level high --groups dependencies; exit 0'",
        "audit:deps:windows": "bash -c 'yarn audit --level high --groups dependencies; exit 0'",
        "test": "yarn lint && yarn audit:deps && yarn test:cov && yarn test:e2e",
        "test:windows": "yarn lint && yarn audit:deps:windows && yarn test:cov && yarn test:e2e",
        "test:cov": "jest src --coverage --forceExit --verbose",
        "test:debug": "node --inspect-brk -r tsconfig-paths/register node_modules/.bin/jest --runInBand",
        "test:e2e": "jest e2e --forceExit --verbose",
        "test:integration:dev": "INTEGRATION_ENV_FILE_PATH=./.env.integration.dev jest integration --verbose",
        "test:integration:uat": "INTEGRATION_ENV_FILE_PATH=./.env.integration.uat jest integration --verbose",
        "test:integration:uat:windows": "@powershell copy .env .env.backup; copy .env.integration.uat .env && jest integration --verbose && @powershell copy .env.backup .env; del .env.backup"
    },
    "dependencies": {
        "@nestjs/common": "8.4.0",
        "@nestjs/core": "8.4.0",
        "@nestjs/jwt": "8.0.0",
        "@nestjs/mongoose": "9.0.3",
        "@nestjs/platform-express": "^8.4.0",
        "@nestjs/schematics": "8.0.8",
        "@nestjs/swagger": "5.2.0",
        "@newrelic/native-metrics": "8.0.0",
        "axios": "0.21.4",
        "class-transformer": "0.3.1",
        "class-validator": "0.12.2",
        "dotenv": "^9.0.2",
        "enforce-peer-dependencies": "1.0.12",
        "fast-xml-parser": "^3.17.4",
        "lodash": "^4.17.19",
        "mongoose": "6.2.4",
        "nest-winston": "1.3.5",
        "newrelic": "^7.3.1",
        "reflect-metadata": "0.1.13",
        "rimraf": "3.0.2",
        "rxjs": "7.1.0",
        "rxjs-etc": "^10.6.0",
        "swagger-ui-express": "4.1.4",
        "winston": "3.3.3"
    },
    "devDependencies": {
        "@nestjs/testing": "8.4.0",
        "@types/express": "4.17.13",
        "@types/jest": "27.4.1",
        "@types/lodash": "^4.14.158",
        "@types/newrelic": "6.4.0",
        "@types/node": "17.0.21",
        "@types/supertest": "2.0.10",
        "@typescript-eslint/eslint-plugin": "5.13.0",
        "@typescript-eslint/eslint-plugin-tslint": "5.13.0",
        "crypto-random-string": "3.2.0",
        "eslint": "8.10.0",
        "eslint-config-airbnb-typescript": "^16.1.0",
        "eslint-config-prettier": "^8.5.0",
        "eslint-import-resolver-typescript": "^2.5.0",
        "eslint-plugin-eslint-comments": "^3.2.0",
        "eslint-plugin-import": "^2.25.4",
        "eslint-plugin-jest": "^26.1.1",
        "eslint-plugin-prettier": "^4.0.0",
        "jest": "27.5.1",
        "jest-circus": "^26.6.3",
        "mongodb-memory-server": "8.4.0",
        "node-forge": "^0.10.0",
        "node-mocks-http": "^1.9.0",
        "package": "1.0.1",
        "prettier": "2.1.2",
        "start-server-webpack-plugin": "2.2.5",
        "supertest": "6.1.3",
        "ts-jest": "27.1.3",
        "ts-loader": "9.2.8",
        "ts-node": "10.7.0",
        "typescript": "4.6.2",
        "webpack": "5.70.0",
        "webpack-cli": "4.9.2",
        "webpack-node-externals": "3.0.0",
        "ts-node-dev": "^1.1.8",
        "tsconfig-paths": "3.14.1"
    },
    "resolutions": {
        "**/axios": "0.21.2",
        "**/follow-redirects": "^1.14.7",
        "**/node-fetch": "^2.6.7"
    }
}

PS: The tests were running and paths were resolving properly prior to version upgrade. My old package.json file looked like below:

{
    "name": "activation",
    "version": "0.0.1",
    "description": "Activation micro-service ",
    "license": "MIT",
    "scripts": {
        "prebuild": "rimraf dist",
        "build": "env NODE_ENV=production webpack",
        "format": "prettier --write \\\"src/**/*.ts\\\" \\\"e2e/**/*.ts\\\"",
        "start": "nest start",
        "start:dev": "env NODE_ENV=local ts-node-dev --respawn --watch .env,.env.local -r tsconfig-paths/register ./src/main.ts",
        "start:debug": "env NODE_ENV=local ts-node-dev --respawn --inspect=4321 --watch .env,.env.local -r tsconfig-paths/register ./src/main.ts",
        "start:prod": "node dist/main",
        "lint": "eslint -c .eslintrc.js --ext .ts .",
        "prettier": "prettier './**/*.ts' --write --list-different",
        "fixlint": "yarn lint --fix",
        "audit:deps": "/bin/bash -c 'yarn audit --level high --groups dependencies; exit 0'",
        "audit:deps:windows": "bash -c 'yarn audit --level high --groups dependencies; exit 0'",
        "test": "yarn lint && yarn audit:deps && yarn test:cov && yarn test:e2e",
        "test:windows": "yarn lint && yarn audit:deps:windows && yarn test:cov && yarn test:e2e",
        "test:cov": "jest src --coverage --forceExit --verbose",
        "test:debug": "node --inspect-brk -r tsconfig-paths/register node_modules/.bin/jest --runInBand",
        "test:e2e": "jest e2e --forceExit --verbose",
        "test:integration:dev": "INTEGRATION_ENV_FILE_PATH=./.env.integration.dev jest integration --verbose",
        "test:integration:uat": "INTEGRATION_ENV_FILE_PATH=./.env.integration.uat jest integration --verbose",
        "test:integration:uat:windows": "@powershell copy .env .env.backup; copy .env.integration.uat .env && jest integration --verbose && @powershell copy .env.backup .env; del .env.backup"
    },
    "dependencies": {
        "@nestjs/common": "^7.6.18",
        "@nestjs/core": "^7.6.5",
        "@nestjs/jwt": "^7.2.0",
        "@nestjs/mongoose": "7.2.3",
        "@nestjs/platform-express": "^7.6.5",
        "@nestjs/schematics": "^7.2.6",
        "@nestjs/swagger": "^4.8.0",
        "@newrelic/native-metrics": "5.2.0",
        "axios": "0.21.4",
        "class-transformer": "0.3.1",
        "class-validator": "0.12.2",
        "dotenv": "^9.0.2",
        "enforce-peer-dependencies": "1.0.12",
        "fast-xml-parser": "^3.17.4",
        "lodash": "^4.17.19",
        "mongoose": "5.13.9",
        "nest-winston": "1.3.5",
        "newrelic": "^7.3.1",
        "reflect-metadata": "0.1.13",
        "rimraf": "3.0.2",
        "rxjs": "^6.6.3",
        "rxjs-etc": "^10.6.0",
        "swagger-ui-express": "4.1.4",
        "winston": "3.3.3"
    },
    "devDependencies": {
        "@nestjs/testing": "7.6.5",
        "@types/express": "4.17.7",
        "@types/jest": "26.0.4",
        "@types/lodash": "^4.14.158",
        "@types/newrelic": "6.4.0",
        "@types/node": "14.0.22",
        "@types/supertest": "2.0.10",
        "@typescript-eslint/eslint-plugin": "^4.1.1",
        "@typescript-eslint/eslint-plugin-tslint": "^4.1.1",
        "crypto-random-string": "3.2.0",
        "eslint": "7.2.0",
        "eslint-config-airbnb-typescript": "^10.0.0",
        "eslint-config-prettier": "^6.11.0",
        "eslint-import-resolver-typescript": "^2.3.0",
        "eslint-plugin-eslint-comments": "^3.2.0",
        "eslint-plugin-import": "^2.22.0",
        "eslint-plugin-jest": "^24.0.1",
        "eslint-plugin-prettier": "^3.1.4",
        "jest": "26.6.1",
        "jest-circus": "^26.6.3",
        "mongodb-memory-server": "6.6.1",
        "node-forge": "^0.10.0",
        "node-mocks-http": "^1.9.0",
        "package": "1.0.1",
        "prettier": "2.0.5",
        "start-server-webpack-plugin": "2.2.5",
        "supertest": "4.0.2",
        "ts-jest": "26.1.1",
        "ts-loader": "8.0.0",
        "ts-node": "8.10.2",
        "typescript": "3.9.6",
        "webpack": "4.43.0",
        "webpack-cli": "3.3.12",
        "webpack-node-externals": "2.5.0",
        "ts-node-dev": "^1.1.8",
        "tsconfig-paths": "^3.11.0"
    },
    "resolutions": {
        "**/axios": "0.21.2",
        "**/follow-redirects": "^1.14.7",
        "**/node-fetch": "^2.6.7"
    }
}

Please help me understand what am I missing here as I am currently out of idea. Thank you

Update - 31-Mar-2022
My .eslintrc.js file (it resides on the same level as base.tsconfig.json file)

module.exports = {
    root: true,
    parser: '@typescript-eslint/parser',
    parserOptions: {
        project:'./base.tsconfig.json',
        // after adding the below line, paths are resolving only       
        // when inside the activation folder; however, my pre 
        // commit lint check is now failing
        tsconfigRootDir: '../../'
    },
    plugins: ['@typescript-eslint', 'regex', 'jest', 'import'],
    extends: [
        'eslint:recommended',
        'airbnb-typescript/base',
        'plugin:eslint-comments/recommended',
        'plugin:jest/recommended',
        'plugin:@typescript-eslint/recommended',
        // 'prettier/@typescript-eslint',
        'plugin:prettier/recommended',
    ],
    ignorePatterns: ['.eslintrc.js', 'base.webpack.config.js', 'base.jest.config.ts'],
    rules: {
        '@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
        // Not compatible with prettier (cannot turn off prettier indent)
        indent: 'off',
        'import/prefer-default-export': 'off',
        // Needs to be turned off to use the @typescript-eslint/no-useless-constructor
        'no-useless-constructor': 'off',
        // Warns for ts imports when .ts is not needed for imports
        'import/extensions': 'off',
        // These three are added by airbnb but require @typescript-eslint/parser
        // The parser builds and AST which significantly slows linting
        '@typescript-eslint/dot-notation': 'off',
        '@typescript-eslint/no-implied-eval': 'off',
        '@typescript-eslint/no-throw-literal': 'off',
        'prefer-destructuring': ['error', { VariableDeclarator: { object: true } }],
        'class-methods-use-this': 'off',
        // Fixed by prettier
        'max-len': [
            'error',
            140,
            4,
            {
                ignoreUrls: true,
                ignoreComments: false,
                ignoreRegExpLiterals: true,
                ignoreStrings: true,
                ignoreTemplateLiterals: true,
            },
        ],
        quotes: 'off',
        '@typescript-eslint/quotes': 'off',
        'no-plusplus': ['error', { allowForLoopAfterthoughts: true }],
        'jest/no-try-expect': ['off'],
        'jest/no-conditional-expect': ['warn'],
        'import/no-extraneous-dependencies': [
            'off',
            { devDependencies: ['**/*spec.ts', '**/jest.config.ts'] },
        ],
        'no-console': ['error', { allow: ['warn', 'error'] }],
        'jest/expect-expect': [
            'warn',
            {
                assertFunctionNames: ['expect', 'verify', 'request.**.expect*'],
            },
        ],
        'no-underscore-dangle': ['error'],
        'no-param-reassign': [2, { props: false }], // this was disabled to allow mongoose model editing
        'new-cap': [2, { properties: false, capIsNew: false }],
    },
    settings: {
        'import/resolver': {
            typescript: {}, // this loads <rootdir>/tsconfig.json to eslint
        },
    },
    overrides: [
        {
            files: ['**/*.model.ts'],
            // We disable this for models because we need to be able to use declaration merging
            // To define our mongoose Model to use with DatabaseModule
            rules: {
                '@typescript-eslint/no-empty-interface': 0,
            },
        },
    ],
};

My root level package.json file (it resides on the same level as base.tsconfig.json file)

{
    "name": "microservices",
    "version": "1.0.0",
    "description": "contains all microservice modules",
    "main": "index.js",
    "scripts": {
        "install-all": "sh ./yarn-all.sh",
        "lint": "eslint -c .eslintrc.js --ext .ts services/**/e2e services/**/src --resolve-plugins-relative-to .",
        "lint-error-only": "eslint -c .eslintrc.js --ext .ts services/**/e2e services/**/src --resolve-plugins-relative-to . --quiet",
        "prettier": "prettier './services/**/*.ts' --write --list-different",
        "lint-staged": "lint-staged"
    },
    "devDependencies": {
        "@typescript-eslint/eslint-plugin": "5.13.0",
        "@typescript-eslint/eslint-plugin-tslint": "5.13.0",
        "@typescript-eslint/parser": "5.13.0",
        "eslint": "8.10.0",
        "eslint-config-airbnb-typescript": "^16.1.0",
        "eslint-config-prettier": "8.5.0",
        "eslint-import-resolver-typescript": "2.5.0",
        "eslint-plugin-eslint-comments": "^3.2.0",
        "eslint-plugin-import": "2.25.4",
        "eslint-plugin-jest": "^26.1.1",
        "eslint-plugin-prettier": "^4.0.0",
        "eslint-plugin-regex": "1.8.0",
        "lint-staged": "^12.3.5",
        "pre-commit": "^1.2.2",
        "prettier": "2.1.2",
        "start-server-webpack-plugin": "2.2.5",
        "terser-webpack-plugin": "^4.1.0",
        "typescript": "4.6.2",
        "webpack": "4.43.0",
        "webpack-cli": "3.3.12",
        "webpack-node-externals": "2.5.0",
        "ts-node-dev": "^1.1.8",
        "tsconfig-paths": "^3.14.1"
    },
    "pre-commit": "lint-staged",
    "lint-staged": {
        "*.ts": [
            "prettier -l --write",
            "eslint -c .eslintrc.js --fix --ext .ts --resolve-plugins-relative-to ."
        ]
    },
    "dependencies": {
        "jest": "27.5.1",
        "ts-jest": "27.1.3"
    },
    "resolutions": {
        "axios": "0.21.4"
    }
}

I still don't understand how to fix the pre-commit lint check. Please help.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source