简体   繁体   English

在路径中找不到模块:相对于“@mui/styled-engine/StyledEngineProvider/StyledEngineProvider.js”的“react/jsx-runtime”

[英]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 卡住了,你可以将reactreact-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.

相关问题 React Jest 无法从“node_modules/@mui/styled-engine/node/index.js”中找到模块“@emotion/styled” - React Jest Cannot find module '@emotion/styled' from 'node_modules/@mui/styled-engine/node/index.js' 找不到模块“react/jsx-runtime”的声明文件 - Could not find a declaration file for module 'react/jsx-runtime' 未捕获的错误:找不到模块'react/jsx-runtime' - Uncaught Error: Cannot find module 'react/jsx-runtime' 未找到模块:无法解析“E:\frontend\node_modules\@mui\styled-engine”中的“@emotion/react” - Module not found: Can't resolve '@emotion/react' in 'E:\frontend\node_modules\@mui\styled-engine' babel 目标到旧版本浏览器,它引发在“react/jsx-runtime”中找不到导出“jsx”(导入为“_jsx”)(可能的导出:__esModule) - babel target to old version browser, it raise export 'jsx' (imported as '_jsx') was not found in 'react/jsx-runtime' (possible exports: __esModule) 已安装 react-dom,但未找到。 `无法在路径中找到模块:'react-dom/client' 相对于` - react-dom installed, but not found. `Could not find module in path: 'react-dom/client' relative to` node.js 无法从相对路径中找到模块 - node.js can't find module from relative path 找不到模块-相对路径 - cannot find module - relative path ModuleNotFoundError(在路径中找不到模块:“./translate.service”相对于“/src/app/app.component.ts”) - ModuleNotFoundError (Could not find module in path: './translate.service' relative to '/src/app/app.component.ts') 导入现有 .jsx 文件时“找不到模块的声明文件” - "Could not find a declaration file for module" when importing existing .jsx files
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM