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

15.4k views Asked by At

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.

6

There are 6 answers

0
Dmitry On

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

0
Victor Karangwa On

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

0
RustyDev On

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"
    }
  ],
6
J.Hpour On

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.

0
Benoit Blanchon On

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

2
Anoesj Sadraee On

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.