Home > Mobile >  VSCode TS2307 Cannot find module
VSCode TS2307 Cannot find module

Time:09-11

Opening a Typescript project in VSCode causes error ts2307 Cannot find module 'react' or its corresponding type declarations. But Webstorm works fine. I created the repo from CRA, the typescript template. Node installed via nvm. I'm using yarn 3.2.3 here and I have enot ejected the CRA.

package.json

{
  "name": "frontend-ts",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^5.14.1",
    "@testing-library/react": "^13.0.0",
    "@testing-library/user-event": "^13.2.1",
    "@types/jest": "^27.0.1",
    "@types/node": "^16.7.13",
    "@types/react": "^18.0.0",
    "@types/react-dom": "^18.0.0",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-scripts": "5.0.1",
    "typescript": "^4.4.2",
    "web-vitals": "^2.1.0"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

enter image description here

CodePudding user response:

You need to install npm i --save-dev @types/react

CodePudding user response:

I noticed I missed the concept of Yarn workspaces. As soon as I implemented this, it was solved! Workspaces allows node_modules to exist somewhere and satisfy VSCode.

  • Related