React Native新手初始化应用遇peer依赖警告,寻求解决方法
Hey there! I remember how frustrating these random dependency warnings felt when I was just starting out with React Native—let's get this sorted for you right away.
What's going on here?
Those warnings are pointing out that several Babel plugins (like @babel/plugin-transform-parameters and @babel/plugin-transform-spread) require a specific version of @babel/core (7.0.0-beta.40) to work, but that core package wasn't installed automatically when you set up your app. Older npm versions don't handle these "peer dependency" requirements automatically, which is why you're seeing this pop up.
Step-by-step solution
First, navigate to your project's root folder if you aren't already there:
cd your-project-name(Swap
your-project-namewith the actual name you used when initializing the app.)Install the exact version of
@babel/corethat the plugins are requesting:npm install @babel/core@7.0.0-beta.40 --save-devIf you still see similar warnings for other Babel plugins after this, just repeat the pattern—install the required peer dependency with the exact version listed in the warning message.
Once the installation finishes, fire up your app again to check if the warnings are gone:
npx react-native run-android # For iOS, use this instead: npx react-native run-ios
A quick note if you're on npm 7+
Newer npm versions (7 and up) do attempt to install peer dependencies automatically, but sometimes they might grab a newer version that doesn't play nice with these older Babel plugins. Installing the exact beta version we outlined will ensure everything matches up correctly.
内容的提问来源于stack exchange,提问作者Haseeb

