[英]Could not find module in path: 'react/jsx-runtime' relative to '@mui/styled-engine/StyledEngineProvider/StyledEngineProvider.js'
I am having this error while creating a new React project with MUI .使用MUI创建新的 React 项目时出现此错误。 I copied this code example from the docs which works on their live Codesandbox but not in my local.
我从适用于他们的实时 Codesandbox 但不在我本地的文档中复制了这个代码示例。 This is the full error message :
这是完整的错误信息:
ModuleNotFoundError
Could not find module in path: 'react/jsx-runtime' relative to '/node_modules/@mui/styled-engine/StyledEngineProvider/StyledEngineProvider.js'
Below is my package.json
:下面是我的
package.json
:
{
"title": "BasicButtons Material Demo",
"scripts": {
"start": "react-scripts start"
},
"name": "BasicButtons Material Demo",
"main": "index.tsx",
"devDependencies": {
"react-scripts": "latest"
},
"dependencies": {
"@emotion/react": "11.6.0",
"@emotion/styled": "11.6.0",
"@mui/material": "5.1.1",
"@types/react": "16.14.21",
"@types/react-dom": "16.9.14",
"react": "16.12.0",
"react-dom": "16.12.0",
"typescript": "4.0.0-beta"
}
}
Per docs , MUI v5 only supports React v17+:根据文档, MUI v5仅支持 React v17+:
MUI supports the most recent versions of React, starting with ^17.0.0 (the one with event delegation at the React root).
MUI 支持最新版本的 React,从 ^17.0.0(在 React 根目录具有事件委托的版本)开始。 Have a look at the older versions for backward compatibility.
查看旧版本的向后兼容性。
The actual reason why this error shows up is because react/jsx-runtime
module only exists in React v17.出现此错误的实际原因是
react/jsx-runtime
模块仅存在于 React v17 中。 If you're stuck with v15 or v16 of React, you can update react
and react-dom
to the latest minor version to fix the error.如果你被 React v15 或 v16 卡住了,你可以将
react
和react-dom
更新到最新的次要版本来修复错误。
Update both packages to the latest version (17+) to fix it:将这两个软件包更新到最新版本 (17+) 以修复它:
npm install react@latest react-dom@latest
If you have to use v16如果您必须使用 v16
npm install react@16.14.0 react-dom@16.14.0
If you have to use v15如果您必须使用 v15
npm install react@15.7.0 react-dom@15.7.0
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.