简体   繁体   English

如何解决由 AWS Amplify 引起的对等依赖问题?

[英]How to resolve a peer dependency issue caused by AWS Amplify?

I am having a problem with my react build, maybe related to AWS amplify, but I'm having trouble pinning it down.我的反应构建有问题,可能与 AWS 放大有关,但我无法确定它。

When it started, I was able to run my program locally without a problem.当它启动时,我能够在本地毫无问题地运行我的程序。 I uploaded it to GitHub and my CI/CD setup with amplify tried to build it.我将它上传到 GitHub,我的带有放大的 CI/CD 设置试图构建它。 Amplify said it broke during the build. Amplify 说它在构建过程中坏了。 At that point I discovered that I couldn't run npm update.那时我发现我无法运行 npm 更新。

I've been messing with it a lot and may have messed up the environment further.我一直在搞砸它,可能进一步搞砸了环境。 If anyone has any advice I'd really appreciate it.如果有人有任何建议,我将不胜感激。

The error I originally encountered was something like this:我最初遇到的错误是这样的:

npm WARN ERESOLVE overriding peer dependency
npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR! 
npm ERR! While resolving: react-drag-drop-files@2.3.7
npm ERR! Found: react@16.14.0
npm ERR! node_modules/react
npm ERR!   peer react@"18.1.0" from react-native@0.70.6
npm ERR!   node_modules/react-native
npm ERR!     peer react-native@">=0.56" from react-native-get-random-values@1.7.0
npm ERR!     node_modules/react-native-get-random-values
npm ERR!       react-native-get-random-values@"^1.4.0" from @aws-sdk/middleware-retry@3.6.1
npm ERR!       node_modules/@aws-sdk/middleware-retry
npm ERR!         @aws-sdk/middleware-retry@"3.6.1" from @aws-sdk/client-cognito-identity@3.6.1
npm ERR!         node_modules/@aws-sdk/client-cognito-identity
npm ERR!         11 more (@aws-sdk/client-comprehend, ...)
npm ERR!     peer react-native@"^0.0.0-0 || 0.60 - 0.71 || 1000.0.0" from @react-native-async-storage/async-storage@1.17.11
npm ERR!     node_modules/@react-native-async-storage/async-storage
npm ERR!       peer @react-native-async-storage/async-storage@"^1.13.0" from @aws-amplify/core@4.0.2
npm ERR!       node_modules/@aws-amplify/core
npm ERR!         @aws-amplify/core@"4.0.2" from @aws-amplify/analytics@5.0.0
npm ERR!         node_modules/@aws-amplify/analytics
npm ERR!         11 more (@aws-amplify/api-graphql, @aws-amplify/api-rest, ...)
npm ERR!       1 more (amazon-cognito-identity-js)
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^18.0.0" from react-drag-drop-files@2.3.7
npm ERR! node_modules/react-drag-drop-files
npm ERR!   react-drag-drop-files@"^2.3.7" from the root project
npm ERR! 
npm ERR! Conflicting peer dependency: react@18.2.0
npm ERR! node_modules/react
npm ERR!   peer react@"^18.0.0" from react-drag-drop-files@2.3.7
npm ERR!   node_modules/react-drag-drop-files
npm ERR!     react-drag-drop-files@"^2.3.7" from the root project

Fully uninstalling react-drag-drop-files didn't help either, it just replaced it with another dependency issue;完全卸载 react-drag-drop-files 也无济于事,它只是用另一个依赖问题代替了它;

The suggestions I saw were mostly reinstall after performing npm config set legacy-peer-deps=true.我看到的建议大多是在执行 npm config set legacy-peer-deps=true 后重新安装。 That didn't seem ideal but I couldn't find a specific description of how to actually resolve the dependency conflict.这看起来并不理想,但我找不到关于如何实际解决依赖冲突的具体描述。 I tried uninstalling and reinstalling the relevant modules but that didn't work.我尝试卸载并重新安装相关模块,但没有用。

Finally I did try enabling legacy peer deps and deleting my modules, then reinstalling.最后我确实尝试启用旧版对等依赖并删除我的模块,然后重新安装。 That also didn't work and left me with this error when trying to run locally:这也没有用,并在尝试在本地运行时给我留下了这个错误:

./node_modules/aws-amplify-react/lib-esm/Amplify-UI/Amplify-UI-Components-React.js Attempted import error: 'a' is not exported from '@aws-amplify/ui' (imported as 'AmplifyUI'). ./node_modules/aws-amplify-react/lib-esm/Amplify-UI/Amplify-UI-Components-React.js 尝试导入错误:“a”未从“@aws-amplify/ui”导出(导入为“放大 UI')。

I wasn't able to resolve that either.我也无法解决这个问题。 So I deleted modules again, ran npm install again, and now I'm back to the original error.所以我再次删除模块,再次运行 npm 安装,现在我又回到了原来的错误。

I had the exact same problem, but using --legacy-peer-deps should work.我遇到了完全相同的问题,但使用 --legacy-peer-deps 应该可以。 You are probably however running it only locally, and not when the application is being built in Amplify.但是,您可能仅在本地运行它,而不是在 Amplify 中构建应用程序时运行它。

Go to your application in AWS Amplify and select Build settings from the sidebar menu. Go 到您在 AWS Amplify 中的应用程序和 select 从侧边栏菜单构建设置。 Next just replace接下来只需更换

preBuild: commands: - npm ci

With:和:

 preBuild: commands: - npm ci --legacy-peer-deps

That did the trick for me at least, hope it helps!这至少对我有用,希望对你有帮助!

Documentation: https://docs.aws.amazon.com/amplify/latest/userguide/build-settings.html文档: https://docs.aws.amazon.com/amplify/latest/userguide/build-settings.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM