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

6

35

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.

Beseech answered 27/7, 2020 at 22:22 Comment(0)
A
33

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.

Atween answered 10/8, 2020 at 9:55 Comment(2)
Seriously! Sometimes VSCode makes no sense. :|Koziol
Restarting VS Code temporarily hides the problem, but it comes back after a while.Diantha
L
28

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.

Lemkul answered 6/1, 2021 at 19:30 Comment(6)
This is 100% the correct answer, thank you SO much. Even including the Restart Extension Host command, which I will be using a LOT. This has been driving me BONKERS :)Perishing
Restart Extension Host rocked my world!Evanthe
I added this to jsconfig and it complained Unknown compiler option 'typeAcquisition' and the problem came back in few secondsBelfry
@Belfry Thanks for reporting, Which version of typescript do you use?Lemkul
I'm not using ts directly, in fact I'm using a jsconfig but I've tried both vscode's version 4.4.3 and node_modules' version 4.5.2 and they both complain about typeAcquisition option in jsconfig. And the original errors comes back after few minutes anywayBelfry
@Belfry Maybe your vscode use another typescript version. As I find in json.schemastore.org/jsconfig, the typeAcquisition Requires TypeScript version 2.1 or later. See code.visualstudio.com/docs/typescript/… for more details.Lemkul
D
12

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

Diantha answered 19/11, 2020 at 15:9 Comment(0)
G
3

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

Geriatric answered 2/8, 2020 at 10:15 Comment(0)
M
1

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

Mordacious answered 20/7, 2021 at 8:42 Comment(0)
T
1

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"
    }
  ],
Theomania answered 24/1, 2022 at 16:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.