Cannot find type definition file for 'types'.
See original GitHub issueI wanted to try using typescript on a newly created Redwood project 0.20.0. I followed the guidance from the typescript page doc and created a page and a component (the component has been created with the --ts
option).
I noticed this issue in the Problems
tab of vs code.


Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (5 by maintainers)
Top Results From Across the Web
error TS2688: Cannot find type definition file for...random paths.
These errors occur when you have subdirectories of a typeRoots directory (in this case node_modules/@types ) that do not contain index.d.ts ...
Read more >Cannot find type definition file for '@types' - Stack Overflow
so i'm building an ionic application for android and ios devices. when i'm trying to build application in android with command 'ionic cordova ......
Read more >Error TS2688: Cannot find type definition file for 'node'
If am receiving this error when running the vtex link command: Webpack for react@3.x builder finished in 464ms with errors: [at-loader] ...
Read more >What do "Cannot find type definition file for x" errors even mean?
npm i @types/x. And It solves this issue, but today I get the error: error TS2688: Cannot find type definition file for 'jsonwebtoken...
Read more >Typescript compiler can t find node with yarn - Edureka
Seems like Typescript can't find the @types/node ... , }] ... Running tsc shows TS2688: Cannot find type definition file for 'node'.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I think I found two workarounds by tweaking the tsconfig.json file a bit. But please keep in mind that I’m certainly not a typescript wizard and you should took it with a pinch of salt 😄
Let’s say I add
yup
package (schema validation helper) as well as its typed package to the redwood web side :yarn workspace web add yup
yarn workspace web add @types/yup -D
1. Add a
types
propertyIf I add the
types
property with an empty array value to tsconfig.json the issue isn’t displayed anymore and I keep the type definition of yup in my IDE.It’s a bit odd since the
types
property doc mentions that only packages listed will be included in the global scope…2. Modify the
typeRoots
propertyAnother workaround I found is to change the
typeRoots
property as followed :"typeRoots": ["../.redwood", "../node_modules/@types"],
This makes more sense to me since I think that only adding
../.redwood
is preventing other@types/.
packages to be included.@thedavidprice,
could we keep this open until a canonical solution is found ?
FWIW the “Modify the
typeRoots
property” referenced above doesn’t seem to work at all. OTOH adding the emptytypes
trick does make the error go away. It’s not clear to me also if this is the right way to do it (as it seems at odds with MS docs - @Krisztiaan any idea on this ?); If it is then thetsconfig.json
snippets at https://redwoodjs.com/docs/typescript.html#typescript should probably be updated so that things work of the box…While on it, why doesn’t
yarn create redwood-app
add thosetsconfig.json
by default ? less friction for users, IMHO.