Fix Cannot find module ‘fs’ or its corresponding type declarations.ts(2307)

Fix Cannot find module ‘fs’ or its corresponding type declarations.ts(2307)

Share

I recently ran into the error “Cannot find module 'fs' or its corresponding type declarations.ts(2307)” while I was using VSCode and I was searching for a fix.

Turns out all I needed to do was to add the definition file for node types in my project.

npm i -D @types/node
Bash

After that, reloading the window fixed the error!

If you are still facing the error, maybe the .tsconfig file needs to be updated too. The types array inside compilerOptions needs to have “node” as a value inside the array.

{
  "compilerOptions": {
    "types": [
      "node"
    ]
  },
}
JSON

And that should hopefully solve the Cannot find module 'fs' or its corresponding type declarations.ts(2307) error.

0
Would love your thoughts, please comment.x
()
x