Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix "File '.../node_modules/dotenv/types' not found." error coming from jsconfig.json?

VSCode is showing errors for jsconfig.json: "File '.../node_modules/dotenv/types' not found."

Appears to be looking for typescript definitions for dotenv, but I'm not using typescript or dotenv (other than in imported packages). And there is a node_modules/dotenv/types folder.

like image 331
Steve Avatar asked Jul 27 '20 22:07

Steve


6 Answers

I had the same issue. Restarting VSCode solved the problem. See: https://github.com/motdotla/dotenv/issues/475

Edit: this seems to be an issue with the contents of dotenv's package.json. There's an open PR, but the author hasn't replied/merged yet at this time. Link: https://github.com/motdotla/dotenv/pull/476

Edit 2: This should now be fixed! dotenv v8.4.0 fixes this issue. See https://github.com/motdotla/dotenv/releases/tag/v8.4.0.

like image 154
Anoesj Sadraee Avatar answered Sep 26 '22 20:09

Anoesj Sadraee


You can exclude type checking for dotenv:

// tsconfig.json or jsconfig.json
"typeAcquisition": {
  "exclude": [ "dotenv" ]
}

In this way, typescript will not see this library for auto-type acquisition and then, vscode error will be fixed.

Keep in mind that the changes affect vscode error after a while. Do not assume that see the fix immediately after changing this option.

To see the affection you can restart vscode extension server (Ctrl+Shift+P And type Restart Extension Host and press Enter) and wait a few minutes to validate the solution.

like image 37
J.Hpour Avatar answered Sep 29 '22 20:09

J.Hpour


The path node_modules/dotenv/types is referenced as the "types" declaration in dotenv's package.json. The problem is that the types declaration should point to a file, not a folder. So it's a problem with dotenv's package, not with VS Code.

There is an opened PR to fix this problem; until it's merged, you can edit node_modules/dotenv/package.json and replace "types": "types" with "types": "types/index.d.ts".

like image 29
Benoit Blanchon Avatar answered Sep 25 '22 20:09

Benoit Blanchon


Just faced the same issue. Deleting node_modules and reinstalling all packages fixed this.

like image 20
Dmitry Avatar answered Sep 29 '22 20:09

Dmitry


I tried all mentioned solutions but none fixed it on my end. So, I tried reopening the code editor and the problem was solved

like image 39
Victor Karangwa Avatar answered Sep 25 '22 20:09

Victor Karangwa


I was running into the same issue and found that adding this to VSCode settings finally fixed it:

  "json.schemas": [
    {
      "$schema": "https://json.schemastore.org/jsconfig"
    }
  ],
like image 21
RustyDev Avatar answered Sep 28 '22 20:09

RustyDev