6

I added a jsconfig.json to my vscode project and for some reason I am getting a typescript error that states "dotenv/types not found".

I cannot for the life of me figure out why I am getting this error. I even tried adding dotenv to my package.json and it did not resolve my issue.

This is a standard project created with create-react-app, and I added the jsconfig.json to allow absolute imports

{
  "compilerOptions": {
    "baseUrl": "src"
  },
  "include": ["src"]
}

Exception:

File '/Users/path/to/file/node_modules/dotenv/types' not found.

Other potential files that might be helpful:

package.json

{
  "name": "quantous-spa",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/react": "^9.3.2",
    "@testing-library/user-event": "^7.1.2",
    "axios": "^0.20.0",
    "babel-plugin-macros": "^2.8.0",
    "react": "^16.13.1",
    "react-dom": "^16.13.1",
    "react-feather": "^2.0.8",
    "react-loading-skeleton": "^2.1.1",
    "react-router-dom": "^5.2.0",
    "react-scripts": "3.4.3",
    "styled-components": "^5.1.1",
    "typeface-muli": "^1.1.3"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "devDependencies": {
    "eslint-config-google": "^0.14.0",
    "eslint-config-prettier": "^6.11.0",
    "eslint-plugin-prettier": "^3.1.4",
    "eslint-plugin-react": "^7.20.6",
    "prettier": "^2.0.5"
  },
  "resolutions": {
    "styled-components": "^5"
  }
}

.eslintrc

{
  "env": {
    "browser": true,
    "es2020": true
  },
  "extends": [
    "plugin:react/recommended",
    "google",
    "plugin:prettier/recommended"
  ],
  "parserOptions": {
    "ecmaFeatures": {
      "jsx": true,
      "js": true
    },
    "ecmaVersion": 11,
    "sourceType": "module"
  },
  "plugins": ["react"],
  "rules": {
    "require-jsdoc": "off"
  },
  "settings": {
    "import/resolver": {
      "node": {
        "paths": ["node_modules", "src/"]
      }
    }
  }
}

screeshot of vscode error

5

3 Answers 3

19

If you're using Visual Studio Code, just disable "Typescript validation" in the settings.

The error should go away.

enter image description here

Sign up to request clarification or add additional context in comments.

8 Comments

Disabling warnings and errors is usually a bad idea
Not if it's TS :)
Especially when the Typescript error is in JavaScript code, I'm having this error on a JavaScript-only project.
@icc97, this worked: why is it a bad idea ? what else can one do to remove the error ?
@D.L errors and warnings are there to help you, turning them all off because of one warning can hurt you in the long run. Better to dig deeper into the specific problem. Types by themselves are useful even if you are just using JavaScript and not Typescript - they provide auto-complete. The warning as far as I know is because the library dotenv doesn't have a types file - one way to fix this is to ask the dotenv library to add a types file which will make this warning go away and help all users of the library.
|
13

The @dioslibre answer works perfectly, but I didn't want to disable the Typescript validation. One alternative, explained by @Anees Hameed in their answer to a similar question is to add the following snippet to the settings.json:

 "json.schemas": [
      { 
        "$schema": "https://json.schemastore.org/jsconfig" 
      }
    ]

Comments

-5

The error is telling you it can't find dotenv types. Run npm install dotenv which installs types.

2 Comments

Thanks for the recommendation - Unfortunately, I had already tried this and it did not resolve my problem. I performed the install as requested, then restarted VSCode and still see the same error.
this answer is not helpful. Dotenv has an open issue github.com/motdotla/dotenv/issues/475

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.