我在解决盖茨比项目中的一个错误。
我在CLI中运行npm update时遇到以下错误:
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! node_modules/react
npm ERR! react@"^18.1.0" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^17.0.2" from simple-react-lightbox@3.6.9-0
npm ERR! node_modules/simple-react-lightbox
npm ERR! simple-react-lightbox@"^3.6.9-0" 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.
当我通过CLI构建(gatsby build)网站时,它可以工作,但当我将其部署到Netlify时,我得到了相同的错误:
4:05:39 PM: npm ERR! code ERESOLVE
4:05:39 PM: npm ERR! ERESOLVE could not resolve
4:05:39 PM: npm ERR!
4:05:39 PM: npm ERR! While resolving: simple-react-lightbox@3.6.9-0
4:05:39 PM: Creating deploy upload records
4:05:39 PM: npm ERR! Found: react@18.1.0
4:05:39 PM: npm ERR! node_modules/react
4:05:39 PM: npm ERR! react@"^18.1.0" from the root project
4:05:39 PM: npm ERR! peer react@">=16.8 || ^17.0.0" from framer-motion@4.1.17
4:05:39 PM: npm ERR! node_modules/framer-motion
4:05:39 PM: npm ERR! framer-motion@"^4.1.17" from simple-react-lightbox@3.6.9-0
4:05:39 PM: npm ERR! node_modules/simple-react-lightbox
4:05:40 PM: Failed during stage 'building site': Build script returned non-zero exit code: 1 (https://ntl.fyi/exit-code-1)
4:05:39 PM: npm ERR! simple-react-lightbox@"^3.6.9-0" from the root project
4:05:39 PM: npm ERR! 15 more (nano-css, react-dom, react-helmet, react-masonry-css, ...)
4:05:39 PM: npm ERR!
4:05:39 PM: npm ERR! Could not resolve dependency:
4:05:39 PM: npm ERR! peer react@"^17.0.2" from simple-react-lightbox@3.6.9-0
4:05:39 PM: npm ERR! node_modules/simple-react-lightbox
4:05:39 PM: npm ERR! simple-react-lightbox@"^3.6.9-0" from the root project
4:05:39 PM: npm ERR!
4:05:39 PM: npm ERR! Conflicting peer dependency: react@17.0.2
4:05:39 PM: npm ERR! node_modules/react
4:05:39 PM: npm ERR! peer react@"^17.0.2" from simple-react-lightbox@3.6.9-0
4:05:39 PM: npm ERR! node_modules/simple-react-lightbox
4:05:39 PM: npm ERR! simple-react-lightbox@"^3.6.9-0" from the root project
4:05:39 PM: npm ERR!
4:05:39 PM: npm ERR! Fix the upstream dependency conflict, or retry
4:05:39 PM: npm ERR! this command with --force, or --legacy-peer-deps
4:05:39 PM: npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
有什么解决办法吗?
2条答案
按热度按时间roejwanj1#
几分钟前我也遇到了类似的问题,但我能够通过使用
--force
标志强制安装来解决它,所以你可以通过以下方式安装它:我认为问题在于,您要安装的依赖项/包是基于react v17.x构建的,而您正在使用react v18.x上的项目
我希望这能解决你的问题。
t8e9dugd2#
我看到这个包已经过时了。不久前就不再支持了。我已经把react从18降到17了。这似乎工作。
https://www.npmjs.com/package/simple-react-lightbox
我的步骤:
1.降级React18至17
(npm install --save react@17.0.2 react-dom@17.0.2)
1.已删除Gatsby缓存
gatsby clean
1.删除node_modules和package-lock.json
1.已重新安装npm
npm install