reactjs 未显示React查询devtools

f5emj3cl  于 2023-03-01  发布在  React
关注(0)|答案(4)|浏览(121)

我目前正在我的项目中使用react query,但是devtools图标没有显示在我的屏幕上。控制台中也没有错误。我目前正在遵循youtube上的教程
下面是我的package.json我也安装了最新的版本。但是我似乎找不到问题。
Package.json

{
  "name": "react-query-starter",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@tanstack/react-query": "^4.0.10",
    "@tanstack/react-query-devtools": "^4.0.10",
    "@testing-library/jest-dom": "^5.11.4",
    "@testing-library/react": "^11.1.0",
    "@testing-library/user-event": "^12.1.10",
    "axios": "^0.21.1",
    "json-server": "^0.16.3",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-router-dom": "^5.2.0",
    "react-scripts": "4.0.3",
    "web-vitals": "^1.0.1"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject",
    "serve-json": "json-server --watch db.json --port 4000"
  },
  "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"
    ]
  }
}

App.js

import { BrowserRouter as Router, Switch, Route, Link } from "react-router-dom"
import "./App.css"
import { QueryClient, QueryClientProvider } from "@tanstack/react-query"
import { ReactQueryDevtools } from "@tanstack/react-query-devtools"
import { HomePage } from "./components/Home.page"
import { RQSuperHeroesPage } from "./components/RQSuperHeroes.page"
import { SuperHeroesPage } from "./components/SuperHeroes.page"

const queryClient = new QueryClient()

function App() {
  return (
    <QueryClientProvider client={queryClient}>
      <Router>
        <div>
          <nav>
            <ul>
              <li>
                <Link to="/">Home</Link>
              </li>
              <li>
                <Link to="/super-heroes">Traditional Super Heroes</Link>
              </li>
              <li>
                <Link to="/rq-super-heroes">RQ Super Heroes</Link>
              </li>
            </ul>
          </nav>
          <Switch>
            <Route path="/super-heroes">
              <SuperHeroesPage />
            </Route>
            <Route path="/rq-super-heroes">
              <RQSuperHeroesPage />
            </Route>
            <Route path="/">
              <HomePage />
            </Route>
          </Switch>
        </div>
      </Router>
      <ReactQueryDevtools initialIsOpen={false} />
    </QueryClientProvider>
  )
}

export default App
mutmk8jj

mutmk8jj1#

看起来这是一个问题,现在修复了这个测试版:https://github.com/TanStack/query/issues/3916#issuecomment-1213172411
我使用了yarn add @tanstack/react-query-devtools@4.0.11-beta.0,我知道这是测试版,但现在显示了devtools

zaqlnxep

zaqlnxep2#

请尝试其他浏览器或检查其是否已更新。如果您正在使用VSCode,请尝试重新启动它。

nukf8bse

nukf8bse3#

我们仍在尝试解决devtools和ESM支持的捆绑问题。主要是,像react-scripts v4这样的旧捆绑包会错误地选择错误的构建版本。如果您切换到react-scripts v5(6个多月前推出)或更现代的vite,一切都会正常工作。我们所有的示例都使用vite,所以您可以看到我们是如何在那里做的。
我们最近做了一个测试版,应该解决这个问题,但它仍然有一些问题,我们正在试图找出它在这里:https://github.com/TanStack/query/issues/3882
tl;dr:捆绑很难,很抱歉出现这些问题。

oxiaedzo

oxiaedzo4#

我也遇到了同样的问题,我无法查看开发工具控制台。下面是我的package.json文件。我不确定它是否与webpack或rollup设置有关,但我找不到任何可能阻止它显示的内容。

{
  "name": "mas-ui",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {
    "start": "nx serve",
    "build": "nx build",
    "test": "nx test"
  },
  "private": true,
  "dependencies": {
    "@babel/preset-typescript": "^7.18.6",
    "@capacitor/app": "^4.1.1",
    "@capacitor/core": "^4.6.3",
    "@capacitor/haptics": "^4.1.0",
    "@capacitor/keyboard": "^4.1.1",
    "@capacitor/local-notifications": "^4.1.5",
    "@capacitor/status-bar": "^4.1.1",
    "@capacitor/storage": "^1.2.5",
    "@emotion/react": "^11.10.5",
    "@emotion/styled": "^11.10.5",
    "@ionic-enterprise/identity-vault": "^5.9.6",
    "@ionic/react": "^6.5.3",
    "@mui/material": "^5.11.8",
    "@mui/x-data-grid": "^5.17.24",
    "@tanstack/react-query": "^4.23.0",
    "@tanstack/react-query-devtools": "^4.0.11-beta.0",
    "axios": "^1.2.3",
    "core-js": "^3.28.0",
    "ionicons": "^6.1.3",
    "luxon": "^3.2.1",
    "react": "18.2.0",
    "react-dom": "18.2.0",
    "react-hook-form": "^7.43.1",
    "react-router": "^6.8.1",
    "react-router-dom": "^6.7.3",
    "regenerator-runtime": "^0.13.11",
    "tslib": "^2.3.0"
  },
  "devDependencies": {
    "@babel/preset-react": "^7.14.5",
    "@capacitor/cli": "^4.6.3",
    "@nrwl/cypress": "^15.6.3",
    "@nrwl/eslint-plugin-nx": "15.6.3",
    "@nrwl/jest": "15.6.3",
    "@nrwl/js": "15.6.3",
    "@nrwl/linter": "15.6.3",
    "@nrwl/react": "15.6.3",
    "@nrwl/rollup": "^15.6.3",
    "@nrwl/webpack": "15.6.3",
    "@nrwl/workspace": "15.6.3",
    "@pmmmwh/react-refresh-webpack-plugin": "^0.5.7",
    "@rollup/plugin-url": "^7.0.0",
    "@svgr/rollup": "^6.1.2",
    "@svgr/webpack": "^6.1.2",
    "@testing-library/react": "13.4.0",
    "@types/jest": "28.1.1",
    "@types/luxon": "^3.2.0",
    "@types/node": "18.11.9",
    "@types/react": "18.0.25",
    "@types/react-dom": "18.0.9",
    "@types/react-router-dom": "5.3.3",
    "@typescript-eslint/eslint-plugin": "^5.36.1",
    "@typescript-eslint/parser": "^5.36.1",
    "babel-jest": "28.1.1",
    "cypress": "^12.2.0",
    "eslint": "~8.15.0",
    "eslint-config-prettier": "8.1.0",
    "eslint-plugin-cypress": "^2.10.3",
    "eslint-plugin-import": "2.26.0",
    "eslint-plugin-jsx-a11y": "6.6.1",
    "eslint-plugin-react": "7.31.11",
    "eslint-plugin-react-hooks": "4.6.0",
    "jest": "28.1.1",
    "jest-environment-jsdom": "28.1.1",
    "nx": "15.6.3",
    "prettier": "^2.6.2",
    "react-refresh": "^0.10.0",
    "react-test-renderer": "18.2.0",
    "ts-jest": "28.0.5",
    "ts-node": "10.9.1",
    "typescript": "~4.8.2",
    "url-loader": "^4.1.1"
  }
}

相关问题