jsconfig.json gives ts errors
Asked Answered
K

6

37

I am having jsconfig.json in my root directory using Nuxt.js project. And I am having an error:

File '/home/mike/Documents/nuxt/node_modules/dotenv/types' not found.
  The file is in the program because:
    Root file specified for compilation

Actually 5 errors in a first line of jsconfig.json: Errors

I don't even use typescript and I didn't set any typescript options while creating Nuxt.js project

jsconfig.json content:

{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "~/*": ["./*"],
      "@/*": ["./*"],
      "~~/*": ["./*"],
      "@@/*": ["./*"]
    }
  },
  "exclude": ["node_modules", ".nuxt", "dist"]
}

I don't understand where they come from. How do I get rid of this errors? There's no option quick fix so I can't ignore errors for entire file

Kempf answered 30/3, 2021 at 9:56 Comment(0)
C
25

After trying several solutions, I have just added "exclude": ["node_modules"] and restarted VScode. The error went away.

Chretien answered 24/5, 2021 at 20:4 Comment(3)
Have you tried putting it on jsconfig.json ?Chretien
I honestly don’t remember what did I do, but the error is gone.Kempf
Seem to be working after adding it to jsconfig.json.Lapotin
S
15

Just reload VSCode by typing ctrl + shift + p then type reload window and it should work.

Sorrento answered 26/1, 2022 at 15:19 Comment(0)
C
10

I ran into this and just exiting and relaunching VSCode (from the icon) seemed to fix it.

I'd originally started via code . so I'm thinking perhaps the instance with the error had picked up a weird env var from my terminal.

Capitally answered 2/9, 2021 at 1:57 Comment(0)
B
5

In my case the problem was that the project is in a subfolder inside monorepo.

So the solution was changing it into add ./ before node_modules:

"exclude": ["./node_modules", ".nuxt", "dist"],
Biotin answered 6/2, 2022 at 7:20 Comment(0)
S
3

Try to install and rebuild project, Hope this will help,

 npm install --save @types/dotenv
Samal answered 30/3, 2021 at 10:24 Comment(4)
Thanks for the suggestion, but I just initialized github repo and the problem disappeared. If the problem will appear again I'll try your solution.Kempf
I sorta figured it out, the error message appears on a fresh start (when I run my PC and open VSCode) and the error message disappears once I commit changes to my GitHub repo. Do you have any idea why would it be like that?Kempf
Strange behavior, not sure why this, but I will suggest install 'types' as suggested above or delete node_modules and package-lock.json and install fresh npm.Samal
adding the types manually gives warning npm WARN deprecated @types/[email protected]: This is a stub types definition. dotenv provides its own type definitions, so you do not need this installed.Reflection
K
0

This error usually comes from different @types (typescript) folders with conflicting versions try to delete the folder from folder & see what happens.

Kipkipling answered 21/4, 2022 at 9:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.