React Native集成Redux后出现TypeError与AppRegistry未注册报错求助
Let's work through your issues step by step—first, the PropTypes error is almost certainly the root cause of the AppRegistry problem, since unhandled runtime errors can block your app from registering properly with React Native's AppRegistry.
1. Fix the _react.PropTypes.arrayOf TypeError
Even though you removed the prop-types dependency and your own code references, this error usually comes from one of two places:
- Stale cache that's holding onto old code references
- Outdated third-party dependencies that still try to import PropTypes from the core
reactpackage (React moved PropTypes to a separateprop-typespackage in v15.5, so old libraries might not be updated)
Here's how to fix it:
- Clear all caches completely:
Run these commands in your project root:# Reset React Native's metro bundler cache npx react-native start --reset-cache # Clear npm's global cache (use yarn cache clean if you use Yarn) npm cache clean --force - Update your Redux-related dependencies:
Old versions ofreact-reduxor related libraries might rely on the deprecated React PropTypes API. Upgrade them with:npm update react-redux redux redux-thunk # Or for Yarn: yarn upgrade react-redux redux redux-thunk - Double-check for hidden PropTypes references:
Do a full project search (e.g., Ctrl+Shift+F in VS Code) forPropTypesorarrayOf—it's easy to miss a reference in a component or utility file that you forgot to update.
2. Fix the AppRegistry Error
This error is almost always a side effect of the earlier TypeError breaking your app's startup flow. Once you fix the PropTypes issue, this should resolve itself. But if it persists:
- Verify your app name matches:
Make sure thenamevalue inapp.jsonis exactly the same as theappNameyou're using inindex.js(case-sensitive!). - Fix the missing
RootStackimport:
In yourMyapp.js, you're rendering<RootStack />but there's no import statement for it! Add the correct import at the top of the file:import RootStack from './path/to/your/RootStack'; // Replace with your actual file path
3. Fix Your Redux Store Configuration (Prevent Future Issues)
Looking at your configureStore.js, there's a small mistake in how you're calling createStore—the order of arguments is wrong. The second parameter should be the initial state, and the third is the middleware enhancer. Your current code is passing middleware as the initial state, which is causing those weird @@redux/INIT logs. Correct it like this:
const configureStore = (initialState) => { const middleware = applyMiddleware(thunk, loggingMiddleware); // Correct order: rootReducer, initialState, enhancer(middleware) return createStore(rootReducer, initialState, middleware); };
Give these steps a try, and your app should start up without those errors!
内容的提问来源于stack exchange,提问作者Ronak Amlani

