React-native-web不随React 18一起安装

kqlmhetl  于 2023-02-19  发布在  React
关注(0)|答案(1)|浏览(165)

npm install react-native-web出现以下错误,我有其他依赖项,但仅针对此依赖项,为同一依赖项创建的bug也被关闭

npm install react-native-web
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: mSales@0.0.1
npm ERR! Found: react@18.1.0
npm ERR! node_modules/react
npm ERR!   react@"18.1.0" from the root project
npm ERR!   peer react@"^17.0.2 || ^18.0.0" from react-native-web@0.18.10
npm ERR!   node_modules/react-native-web
npm ERR!     react-native-web@"^0.18.10" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^18.2.0" from react-dom@18.2.0
npm ERR! node_modules/react-dom
npm ERR!   peer react-dom@"^17.0.2 || ^18.0.0" from react-native-web@0.18.10
npm ERR!   node_modules/react-native-web
npm ERR!     react-native-web@"^0.18.10" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.

下面是一个docker文件示例

FROM node:alpine
RUN mkdir /app
WORKDIR /app
COPY package.json /app
RUN npm install react-native-web
COPY . /app
EXPOSE 8080
CMD [ "npm", "run", "web" ]
wh6knrhe

wh6knrhe1#

你的react和react-dom版本不匹配。

npm install react-dom@18.1.0 react-native-web@0.18.10

相关问题