无法解决 mui 中的“react/jsx-runtime”,react 18

Can't resolve 'react/jsx-runtime' in mui, react 18

提问人:Ирина Грачева 提问时间:8/2/2022 最后编辑:Drew ReeseИрина Грачева 更新时间:8/2/2022 访问量:1229

问:

当我通过 yarn start 启动应用程序时,无法解析 react 版本 18.2.0 和 mui 版本 5.9.3 的 mui 包中的“react/jsx-runtime” 我启动应用程序 vi cross-env

cross-env NODE_ENV=development webpack serve --config webpack.dev.config.js --progress

我正在使用 React.FC:

import { Select } from "@mui/material";
import MenuItem from "@mui/material/MenuItem";
import React from "react";
const products = [
    "123",
    "234,
    "345",
    "567",
    "678",
  ];
export const App: React.FC = () => {
  return (
    <>
      <Select
        value={"value"}
        onChange={() => console.log("React")}
        label="ProductId"
      >
        { products.map((product, index) => {
          return (
            <MenuItem key={index} value={product}>
              {product}
            </MenuItem>
          );
        })}
      </Select>
    </>
  );
};

export default App;

我有package.json:

...
    "@emotion/react": "^11.10.0",
    "@emotion/styled": "^11.10.0",
    "@mui/icons-material": "^5.8.4",
    "@mui/material": "^5.9.3",
     "react": "^18.2.0",
    "react-device-detect": "^2.1.2",
    "react-dom": "^18.2.0",
    "react-hot-loader": "^4.13.0",
    "react-jss": "^10.9.0"
...

我有tsconfig.json:

 "include": ["src", "tests"],
  "exclude": ["**/node_modules"],
  "compilerOptions": {
    "resolveJsonModule": true,
    "rootDir": "./src",
    "sourceRoot": "./src",
    "declaration": false,
    "types": ["jest", "node"],
    "allowSyntheticDefaultImports": true,
    "emitDecoratorMetadata": false,
    "experimentalDecorators": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "node",
    "noFallthroughCasesInSwitch": true,
    "noImplicitAny": true,
    "noImplicitReturns": true,
    "noUnusedLocals": true,
    "noImplicitOverride": true,
    "noUnusedParameters": true,
    "pretty": true,
    "removeComments": true,
    "sourceMap": true,
    "strictNullChecks": true,
    "stripInternal": true,
    "target": "esnext",
    "jsx": "react-jsx",
    "lib": ["esnext", "dom"],
    "strict": true

我有一个错误:

Module not found: Error: Can't resolve 'react/jsx-runtime' in '/Users/igracheva/dpa-ui/app/node_modules/@mui/material/Select'

我的react js无法正常启动。它写了一个错误“无法解析'react/jsx-runtime'”

reactjs material-ui

评论

0赞 Емил Цоков 8/2/2022
您在使用 Create React 应用程序吗?reactjs.org/docs/create-a-new-react-app.html#create-react-app 如果没有,请考虑一下。你以前跑过吗?yarnyarn start
0赞 Ирина Грачева 8/3/2022
我正在使用现有应用程序。创建新的 react 应用程序只是创建应用程序的框架。我可以在没有创建react的情况下创建项目。我正在使用 npm 而不是 yarn
0赞 Емил Цоков 8/3/2022
好的,那你先跑成功了吗?npm install
0赞 Ирина Грачева 8/4/2022
是的,我首先成功运行了npm install
0赞 Емил Цоков 8/4/2022
你能为你的应用提供代码沙盒吗?还可以在此处查看答案以获取一些想法。stackoverflow.com/questions/65527359/......

答: 暂无答案