question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot find type definition file for 'types'.

See original GitHub issue

I 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.

Capture d’écran 2020-10-25 à 12 06 06 Capture d’écran 2020-10-25 à 12 06 30

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

7reactions
fveauvycommented, Oct 30, 2020

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 property

If 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.

{
  "compilerOptions": {
    "noEmit": true,
    "allowJs": true,
    "esModuleInterop": true,
    "target": "esnext",
    "module": "esnext",
    "moduleResolution": "node",
    "jsx": "preserve",
    "baseUrl": "./",
    "paths": {
      "src/*": ["./src/*"]
    },
    "typeRoots": ["../.redwood"],
    "types": []
  },
  "include": ["src"]
}

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 property

Another 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.

1reaction
AntonioMeirelescommented, Dec 4, 2020

@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 empty types 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 the tsconfig.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 those tsconfig.json by default ? less friction for users, IMHO.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found