admin管理员组

文章数量:1194549

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/"]
      }
    }
  }
}

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/"]
      }
    }
  }
}

Share Improve this question edited Apr 13, 2023 at 7:34 icc97 12.8k9 gold badges83 silver badges96 bronze badges asked Aug 21, 2020 at 15:31 HJordan35HJordan35 2401 gold badge4 silver badges11 bronze badges 5
  • 1 Please, post text as text, not as photographs of text. We want to copy&paste&run your code, copy&paste your inputs, read your outputs, and copy&paste&google your error messages, not critique your use of color and perspective. Also, please make sure to post everything relevant to answering your question in your question, not on some third-party site somewhere else. idownvotedbecau.se/imageofcode idownvotedbecau.se/imageofanexception – Jörg W Mittag Commented Aug 22, 2020 at 6:31
  • Sorry - I updated my question with your requests...Hopefully you can lend a bit of help this time. Turns out my original solution of hard-resetting VSCode did not resolve my issue - the issue came back after a short period of time. – HJordan35 Commented Aug 27, 2020 at 22:24
  • Did you try this solution: stackoverflow.com/a/63605572/14172763 Let me know if can't solve it. – Gustavo Graeff Commented Sep 1, 2020 at 15:01
  • Does this answer your question? How to fix "File '.../node_modules/dotenv/types' not found." error coming from jsconfig.json? – icc97 Commented Apr 12, 2023 at 17:54
  • From the linked answer dotenv had an open issue github.com/motdotla/dotenv/issues/475 that's generated a few SO questions – icc97 Commented Apr 12, 2023 at 17:56
Add a comment  | 

3 Answers 3

Reset to default 19

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

The error should go away.

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" 
      }
    ]

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

本文标签: javascriptSeeing unknown typescript error in JSConfigjson fileStack Overflow