TypeScript: error TS2688: Cannot find type definition file for...random paths.
Using https://github.com/atrauzzi/gerty on the branch hashi-gerty.
Basically anything that tries to do typescript gets a bunch of errors about not finding type definitions I never reference in any of my source files.
(For the simplest example, I do a yarn install and then ./node_modules/.bin/ts-node.)
PS C:\Users\atrauzzi\Development\atrauzzi\gerty> .\node_modules\.bin\ts-node
> console.log('hi');
error TS2688: Cannot find type definition file for '.github'.
error TS2688: Cannot find type definition file for 'build'.
error TS2688: Cannot find type definition file for 'examples'.
error TS2688: Cannot find type definition file for 'scripts'.
error TS2688: Cannot find type definition file for 'src'.
error TS2688: Cannot find type definition file for 'website'.
undefined
>
Apologies, I have searched for this, but wasn’t able to find anything relevant or within the last few months.
What is happening and why am I getting these weird errors? Is there any way they can be improved if it is in fact something that I’ve done wrong?
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 47
- Comments: 56 (5 by maintainers)
Commits related to this issue
- Build many bug fixes (#100) * Allow core to be built on latest node version - Use `>12` instead of `^12` * Add quotes to copyfiles in package.json - On MacOS the quotes are necessary - Result i... — committed to InteropIO/finsemble-seed by deleted user 4 years ago
- fix: TS2688 https://github.com/microsoft/TypeScript/issues/27956 > These errors occur when you have subdirectories of a typeRoots directory…that do not contain index.d.ts files. — committed to primer/react by smockle 3 years ago
- ui: generate single dts file for user-facing library and bundle library with esbuild Signed-off-by: Mat Appelman <mat@opstrace.com> — committed to opstrace/opstrace by MatApple 3 years ago
- To fix issue reported in https://github.com/microsoft/TypeScript/issues/27956 — committed to dirslashls/sqlframes-react-demo by dirslashls 3 years ago
- build(ts): remove `typeRoots` See https://github.com/microsoft/TypeScript/issues/27956. — committed to LittleYe233/musichub-backend by LittleYe233 2 years ago
- fix(tsconfig): fix cannot find type definition https://github.com/microsoft/TypeScript/issues/27956#issuecomment-788477941 — committed to NguyenHoangKaiser/template by NguyenHoangKaiser 2 years ago
These errors occur when you have subdirectories of a
typeRootsdirectory (in this casenode_modules/@types) that do not containindex.d.tsfiles. I agree the error message is mysterious and should be improved.In your case, the errors occur because your
package.jsonspecifies a package named@types/, which is a silly thing to do.I have this error today! But the code still got compiled to js 😶
I met the same problem (‘cannot find the definition file for “babel__core”’) as you guys, but I googled it and I found the solution which works for me. 编译typescript出现 Cannot find type definition file for ‘babel__core‘
For those who cannot read Chinese, the solution is :
"skipLibCheck": true,in"compilerOptions"in your tsconfig.jsontypeRootsin"compilerOptions"in your tsconfig.jsonIn my case, originally I had
"skipLibCheck": true,when I met this problem, so this time, I add"typeRoots"which solved my problem.This is what I used that appears to remedy this type of error for me. If types is specified, only packages listed will be included. For instance: { “compilerOptions”: { “types” : [“node”, “lodash”, “express”] } } This tsconfig.json file will only include ./node_modules/@types/node, ./node_modules/@types/lodash and ./node_modules/@types/express. Other packages under node_modules/@types/* will not be included. A types package is a folder with a file called index.d.ts or a folder with a package.json that has a types field.
I got this problem too and my case is different. My project has the following file structure:
The frontend working directory is
frontend, it has thenode_modulesdirectory inside and all the commands are run from this directory. I accidentally rannpm install somethingwhile being in the root directory so an excessnode_modulesdirectory appeared:And then when I ran
cd frontend && tsc --noEmitI got theTS2688error.I fixed the error by deleting the
node_modulesdirectory from the project root.Sorry for do not having time read through all comments here. I think this error just indicated you:
I have fixed this by adding
"baseUrl": "."in mytsconfig.jsonfileProposed new errors:
typesis not specified (this seems to be the case that mystifies the most users):Subdirectory '{0}' of 'typeRoots' directory '{1}' is not a valid types package. If the presence of this subdirectory is intentional, change the 'typeRoots' or 'types' option. See https://www.typescriptlang.org/docs/handbook/tsconfig-json.html#types-typeroots-and-types .typesis specified:Could not find a types package named '{0}' (specified in the 'types' option) in any directory specified by the 'typeRoots' option. See https://www.typescriptlang.org/docs/handbook/tsconfig-json.html#types-typeroots-and-types .(Of course, the long link could be replaced with an aka.ms link.)
it worked for me thank you!, 2nd option was the one who worked for me.
This should probably be a warning rather than an error. A missing typedef is equivalent to an empty typedef, which isn’t an error condition.
This worked for me https://stackoverflow.com/a/72759322/13987596
Aha! Doh!
My apologies, clearly that’s a yarn add gone wrong. Yes, very silly indeed.
Feel free to use my blunder-ticket to track improving any feedback 😉
I had a similar problem in a project where a library added native types, fixed by removing its @types/ lib.
In my case the library was yup, so removing @types/yup fixed the error.
Typescript authors: the error message is not helpful. It would be nice to detect overlapping types and give an error about a conflict, perhaps like “Try removing the @types library if one is installed”. 👍
The entry
"@types/": "reach/router"caused https://github.com/reach/router to be downloaded directly into thenode_modules/@typesfolder, creating new files and subdirectories unrecognized by the TypeScript compiler alongside the existing valid subdirectories. I’m guessing you ranyarn add @types/@reach/router, trying to install the@typespackage for the scoped package@reach/router, but that command is actually parsed as installing a package named@types/at versionreach/router. You probably meant@types/reach__router: that’s the naming convention for@typespackages for scoped packages. Consider filing a bug against Yarn for letting you install a package with the invalid name@types/. (I notice that NPM correctly catches this.)**Solution of above error ** Run this : npm install @types/node --save-dev
and in tsconfig file add :
{ “compilerOptions”: { “types”: [“node”] } }
i have the same error but on jsconfig.json file, for no aparent reason, i don’t use babel or any other transpiler on my project, because its a very simple static website, and this is what i have on my jsconfig file, and it’s reporting an “unexpected” error, i don’t use babel, or any other transpiler, how can i get rid of this error? or is this a bug?
This is still a problem, I get
Cannot find type definition file for 'node_modules'.I have
"typeRoots": [ "./node_modules/@types","baseUrl": ".","moduleResolution": "node",So basically I tried all methods above, nothing works. And this error message is still a cipher in 2021.
That’s the only way that works for me.
I tried all other ways above, but none of them worked.
Big thanks!
This worked for me. Thank you!
JUST FYI for Everyone:
I found this thread reading having this same issues. But in mine i had removed the library and @type file as no longer needed. I was still getting this error.
Restarting VSCODE and it went away
Exact same thing happened to me as @mattmccutchen describes. Also ran
yarn add @types/@scoped/package, and suddenly you have@types/as dependency and these weird errors. Would be nice if we get a more descriptive error.@houh60 damn. it worked for me too LOL! Sometimes modern problems required not-so-modern solutions.
So… what’s the best strategy to tackle the need for
index.d.ts? I currently keep an emptyindex.d.ts, with just a link to this issue as a comment. Next to it, I keep a bunch of smaller d.ts files.I am not really happy with the empty index file strategy, but it seems to help - otherwise I simply can’t have a bunch of smaller d.ts files in my project’s
types/folder and TS2688 bites me…O mesmo erro aconteceu comigo, nisso ao ler esse fórum inclui a opção 2 do nosso amigo acima e deu super certo, obrigada!
Opção 2: adicionar typeRoots em “compilerOptions” em seu tsconfig.json
{ “compilerOptions”: { “typeRoots”: [ “node_modules/@types”, “src/typings” ] } }
For me None of the above solutions worked! the case occured when I was installing xero-node My observations,
node_modules/@types/keyvkeyv provides its own type definitions, so you don't need @types/keyv installed!Fix: Remove the keyv folder from node_modules/@types and try to build again! It worked for me!
I reached the same situation, where I need to add a root to look into for declaration file (typing a cordova plugin and need global access)
Same error, I have a tsconfig in a Cypress folder and one in root.
Ok. Thanks for your feedback. If you solved your problem, then why are you telling me? Why not just published it as a check that developers need to ascertain and forget it?
On Wed, Jan 8, 2020 at 5:18 AM Su notifications@github.com wrote:
Within the Typescript documentation with the section on compiler options ‘types’, it worked for me to create the types: [“anymatch”. “lodash”, …] compiler option in tsconfig.json to eliminate this error. I am using Visual Studio code. As you know this may or may not work for you. https://www.typescriptlang.org/docs/handbook/tsconfig-json.html
TypeScript looks in
node_modules/@typesby default since this is where types packages from DefinitelyTyped containing global declarations (such as@types/node, to give one popular example) are normally installed. See the documentation.