-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Unused @types files installed by node modules pollutes and breaks the main project #31148
Comments
Another problem caused by #8836. |
Namely with client-side projects current TypeScript can't use npm packages bundling their own type definition files which depend on @types/node even when they are not compile targets (e.g. An npm package which is used only in build scripts written in JavaScript such as |
@DanielRosenwasser What is your thought after you deleted your comment? Self-bundled type definition files are going to destroy TypeScript on npm. You have to address this serious design problem ASAP. You can take a temporary measure. |
FYI, If you wanna disable the automatic inclusion of definitions from the project's |
I can't use that workaround because of depending some @types packages: https://github.com/falsandtru/spica/blob/v0.0.247/package.json#L45-L47. @DanielRosenwasser commented the same workaround but he deleted it. Probably he thought this is not a good workaround because of this problem.
So you shouldn't use the same folder for @types installed by node modules (especially only for build scripts). To exclude them from default compile targets you should use a different and separated folder. |
That's fine, just use |
Of course I know it but such wasteful additional work will be a bad user experience. This problem must be resolved at upstream. |
I propose that referring package.json like |
@weswigham the problem is that the packages include the |
If you pick up @types packages from package.json, you don't refer other unnecessary packages. Thoughts? |
How is that a problem? If a file has a triple slash reference to other types, then it has a hard dependency on them, and needs them present... |
The problem is separating or filtering, not installing. |
Can you label this issue "bug" to inform this problem of package developers? |
@falsandtru If anything you should go report a bug on the type definitions that have a
If we ever read a |
For instance,
Then you have to find another solution. |
I mean, if it needs the dependency it needs it, and it's up to you (the consumer) to split your environments up - be that via separate |
No, this problem appears with very common, correct, and typical usage. Resolving this problem is a responsibility of TypeScript. This is one of design-level problem based on #8836. |
That is, to use TypeScript, do you really require developers to make another separated environment to use build scripts written in JavaScript? It is nonsense. |
Strictly we don't, but if you don't, there's a chance you need to pass an explicit |
The problem is that chance will be indispensable sooner or later. You didn't have expected such an ending. You have a grace period but you would lose it if you don't address this problem. |
This issue has been marked as 'External' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
At least this is not an external problem. |
Mmmmmm, it is an external problem. I'm going to reiterate for people who find this thread: There is no bug in TS's behavior. When not overridden, TS will load all type definitions in your {
"compilerOptions": {
"strict": true,
"target": "es6",
"module": "commonjs",
"types": ["node"]
}
} TL;DR: Pass |
A key point is |
Therefore, the current |
You only need to list packages with globals that aren't explicitly imported, not every package. Things you explicitly import need not be explicitly included via
The alternative is worse. (And we could only even consider it recently) - imagine if the behavior of Working out the dependency tree from a package.json wouldn't magically be any better, either - we'd still see that you depend on There is no change we can make here that qualifies as a "solution" where nobody has to write any config down, and we already have a solution that requires a minimal amount of config. We only ask that you provide the name(s) of the ambient definition packages which are not directly depended upon by references in your code, so that we may load only those specified and those your code actively references (via |
Indeed, the cost is reduced. However, developers have to define globals or an empty list anyway.
I currently have no suggestions. So I currently don't request any concrete solution. I'm just saying you have to resolve this problem.
If you can't find a solution that requires no additional efforts, I also give up. I write down the original issue #18588 but you shouldn't label that issue with external. That is in discussion although it is strange to you. Can you stop to make arbitrary wrong decisions? |
I have specified |
TypeScript version: 4.1.5 This is my {
"$schema": "https://json.schemastore.org/tsconfig",
"compilerOptions": {
"allowJs": false,
"allowSyntheticDefaultImports": true,
"allowUnreachableCode": true,
"assumeChangesOnlyAffectDirectDependencies": true,
"baseUrl": ".",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"importHelpers": true,
"importsNotUsedAsValues": "error",
"incremental": true,
"isolatedModules": true,
"jsx": "preserve",
"module": "ESNext",
"moduleResolution": "node",
"noEmit": true,
"noImplicitAny": true,
"noUncheckedIndexedAccess": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"preserveSymlinks": true,
"removeComments": true,
"resolveJsonModule": true,
"rootDir": "./src",
"skipLibCheck": true,
"sourceMap": false,
"strict": true,
"target": "ESNext",
"typeRoots": [],
"types": []
},
"include": ["./src/**/*.ts", "./src/**/*.tsx"],
"exclude": ["./src/assets"]
} Still it picks up |
If you grab a TypeScript nightly or TypeScript 4.2 RC, we have an |
@DanielRosenwasser I found out the issue, and I don't know if it's typescript's issue or my dependencies, it feels like typescript's though 🤷 So I found with that very extensive
When I removed one, and ran my particular package "offenders" are:
|
@DanielRosenwasser do you agree that this sounds like a typescript issue? Does it deserve a new issue to be opened? |
Even when we don't use it in the main project. For instance, I'm using
del
package only in the build script file and it is .js file not .ts file.https://github.com/falsandtru/pjax-api/blob/master/gulpfile.js
But it polluted and broke the main project:
https://travis-ci.org/falsandtru/pjax-api/jobs/525654172#L512
This is caused by sindresorhus/del@0361dcc.
You shouldn't automatically include unused/unimported @types files installed by node modules in the compile targets because they usually won't be used when they are not imported explicitly (regardless of direct or indirect). Or you should provide a way to exclude unexpected @types files by tsconfig.json to avoid this problem as a temporary workaround.
TypeScript Version: 3.4.0-dev.20190425
Search Terms:
Code
You can reproduce this problem also with https://github.com/falsandtru/spica.
npm i
npm i del@4.1.1
gulp ts:dist
Expected behavior:
pass
Actual behavior:
Playground Link:
Related Issues:
The text was updated successfully, but these errors were encountered: