Skip to content

TypeScript exclude node_modules not working at all #46634

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

Closed
xgqfrms opened this issue Nov 2, 2021 · 8 comments
Closed

TypeScript exclude node_modules not working at all #46634

xgqfrms opened this issue Nov 2, 2021 · 8 comments
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@xgqfrms
Copy link

xgqfrms commented Nov 2, 2021

TypeScript exclude node_modules not working at all

Bug Report

https://github.com/microsoft/TypeScript-Website/blob/v2/packages/documentation/copy/en/project-config/tsconfig.json.md

{
    "compilerOptions": {
        "target": "es5",
        "lib": [
            "dom",
            "dom.iterable",
            "esnext"
        ],
        "allowJs": true,
        "skipLibCheck": true,
        "esModuleInterop": true,
        "allowSyntheticDefaultImports": true,
        "strict": true,
        "forceConsistentCasingInFileNames": true,
        "noFallthroughCasesInSwitch": true,
        "module": "esnext",
        "moduleResolution": "node",
        "resolveJsonModule": true,
        "isolatedModules": true,
        "noEmit": false,
        "jsx": "react",
        "outDir": "./dist/",
        "baseUrl": "./",
        "paths": {
            "@/*": ["src/*"],
            "@/components/*": ["src/components/*"]
        },
    },
    "include": [
        "./src/**/*"
    ],
    "exclude": [
        "node_modules"
    ],

}
$ cd test

$ tsc -v
# Version 4.1.3

$ node -v
# v12.18.0

$ tsc ./test.ts

image

https://github.community/t/typescript-exclude-node-modules-not-working/209865

@xgqfrms
Copy link
Author

xgqfrms commented Nov 2, 2021

solution

just add --skipLibCheck params in the CLI

# 
$ tsc --skipLibCheck ./test.ts

@xgqfrms xgqfrms closed this as completed Nov 2, 2021
@ritschwumm
Copy link

wait, do you say if you add it in the compilerOptions is doesn't work, but as a command line parameter it does? that would be.... surprising.

@xgqfrms
Copy link
Author

xgqfrms commented Nov 2, 2021

wait, do you say if you add it in the compilerOptions is doesn't work, but as a command line parameter it does? that would be.... surprising.

that's right.

@andrewbranch andrewbranch added the Working as Intended The behavior described is the intended behavior; this is not a bug label Nov 3, 2021
@andrewbranch
Copy link
Member

Your tsconfig is completely ignored when you specify files on the command line instead of -p.

$ tsc --showConfig ./test.ts
{
    "compilerOptions": {},
    "files": [
        "./test.ts"
    ]
}

@xgqfrms
Copy link
Author

xgqfrms commented Nov 5, 2021

@andrewbranch without the files key , it's still has that question.

image

@andrewbranch
Copy link
Member

@xgqfrms
Copy link
Author

xgqfrms commented Nov 6, 2021

not work, too

{
    "compilerOptions": {
        "target": "es5",
        "lib": [
            "dom",
            "dom.iterable",
            "esnext"
        ],
        "allowJs": true,
        "skipLibCheck": true,
        "esModuleInterop": true,
        "allowSyntheticDefaultImports": true,
        "strict": true,
        "forceConsistentCasingInFileNames": true,
        "noFallthroughCasesInSwitch": true,
        "module": "esnext",
        "moduleResolution": "node",
        "resolveJsonModule": true,
        "isolatedModules": true,
        "noEmit": false,
        "jsx": "react",
        "outDir": "./dist/",
        "baseUrl": "./",
        "paths": {
            "@/*": ["src/*"],
            "@/components/*": ["src/components/*"]
        },
        "types": []
    },
    "include": [
        "./src/**/*"
    ],
    "exclude": [
        "node_modules"
    ],
    "files": [
        "./test.ts"
    ]
}

image

@andrewbranch
Copy link
Member

andrewbranch commented Nov 9, 2021

Use --explainFiles to show why every file is included. You cannot prevent the inclusion of files that are included by other files. All of this is working as intended and explained in the docs. If you still have questions after reading them, please ask on StackOverflow or the TypeScript Discord. This issue tracker is not a good place to get support. If you file something here, you need to thoroughly search for duplicates and completely fill out the issue template. Thank you for understanding.

@microsoft microsoft locked as resolved and limited conversation to collaborators Nov 9, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

3 participants