reactjs 为什么react-app(在typescript中)在编辑时不能热重新加载

bxpogfeg  于 5个月前  发布在  React
关注(0)|答案(1)|浏览(59)

有三种情况。都发生在Windows 10 WSL Ubuntu上:
1.本周我用--template typescript创建了一个新的React应用。在yarn start ing之后,各种编辑都不会触发任何热重载。
1.我yarn start艾德编辑了一个旧的React应用程序(使用--template typescript创建),该应用程序创建于2020年7月。package.jsontsconfig.json上的插件自创建以来没有修改,但无法触发热重新加载。
package.json(2020年7月构建)

{
  "name": "00_test",
  "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",
    "@types/jest": "^24.0.0",
    "@types/node": "^12.0.0",
    "@types/react": "^16.9.0",
    "@types/react-dom": "^16.9.0",
    "react": "^16.13.1",
    "react-dom": "^16.13.1",
    "react-scripts": "3.4.1",
    "typescript": "^3.7.2",
    "web-vitals": "^1.1.0"
  },
  "scripts": {
    "start": "PORT=4000 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"
    ]
  }
}

字符串
tsv.json(2020年7月构建)

{
  "compilerOptions": {
    "target": "es5",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noFallthroughCasesInSwitch": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react-jsx"
  },
  "include": [
    "src"
  ]
}


1.我这周创建了一个新的react应用程序(仅使用js),在yarn start ing之后,各种编辑都不会触发任何热重装。
奇怪的是,在所有3种情况下,没有通常的自动弹出一个新的浏览器被触发后编译成功!
我在google上搜索了很多,但只找到一个不适用的案例(指定为webpack问题)。react的github页面没有显示类似的问题。
我的env从2020年7月到现在的变化:
1.一个新的华硕wifi路由器(AC 68 U)与复杂的网络配置选项使用;

  1. VS代码升级到v1.53.1(2021年1月版本);
  2. Windows 10继续升级;
    1.使用WSL 2代替WSL 1;
    1.添加nvm来管理nodejs版本
uelo1irk

uelo1irk1#

问题出在WSL 2上。请尝试将版本设置为版本1。
这里有一个链接到所有步骤的答案:
https://stackoverflow.com/a/66773488/4261884

相关问题