我遇到了React构建方面的问题,可能与AWS Amplify有关,但我无法准确定位。
一开始,我可以在本地运行我的程序,没有任何问题。然后,我将它上传到GitHub,并使用Amplify进行CI/CD设置以构建它。Amplify说在构建过程中出现了错误。这时我发现我不能运行npm update。
我已经尝试很多方法,但可能进一步破坏了环境。如果有人有什么建议,我会非常感激。
我最初遇到的错误类似于以下内容:
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
完全卸载react-drag-drop-files并没有帮助,它仅用另一个依赖问题替代了它;
我看到的建议大多是在执行npm config set legacy-peer-deps=true后重新安装。那似乎不是理想的解决方法,但我找不到如何实际解决依赖冲突的具体描述。我尝试卸载和重新安装相关模块,但那并没有起作用。
最后,我尝试启用legacy peer deps并删除我的模块,然后重新安装。那也没有起作用,并在尝试本地运行时留下了这个错误:
./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').
我也无法解决那个问题。所以我再次删除了模块,重新运行npm install,现在我回到了最初的错误。