升级Expo SDK26时出现Super表达式错误,求解决方案(从SDK21升级)
Hey there, let's tackle this frustrating error you're hitting post-upgrade. That "Super expression must either be null or a function, not number" message almost always traces back to component inheritance issues or mismatched dependencies—let's walk through actionable fixes step by step.
First, Rule Out Dependency Cache & Installation Issues
Old dependency leftovers are a common culprit during upgrades. Let's start with a clean install:
- Delete your
node_modulesfolder and lock file:# For npm users rm -rf node_modules package-lock.json # For yarn users rm -rf node_modules yarn.lock - Reinstall dependencies:
npm install # Or yarn install - Clear Expo's local cache to avoid stale build artifacts:
expo r -c
Check Component Inheritance Syntax
Double-check all your custom components to ensure they're correctly extending React's base components. It's easy to accidentally introduce typos during upgrades—look for any code that looks like this (yes, it happens!):
// ❌ Wrong: Accidental number instead of React.Component class HomeScreen extends 123 { render() { return <View />; } }
Do a global search for extends in your codebase to spot any odd inheritance targets. All components should extend either React.Component or React.PureComponent, with correct imports at the top of each file:
// ✅ Correct import React, { Component } from 'react'; class HomeScreen extends Component { // ... }
Validate React-Navigation Compatibility
You upgraded to react-navigation@1.5.8, which is compatible with SDK 26, but let's confirm your navigation setup isn't using deprecated APIs:
- Ensure you're importing navigation components correctly:
import { StackNavigator, TabNavigator } from 'react-navigation'; - Avoid any legacy configuration props that were removed between v1.0.0-beta.21 and v1.5.8. For example, some older
StackNavigatoroptions like header-related props had syntax tweaks—double-check your route configurations match the expected structure for this version.
Check Third-Party Library Compatibility
If you're using any other npm packages (like UI kits, state management tools, etc.), verify they support Expo SDK 26 and React 16.3.0-alpha.1. Old libraries built for React Native 0.48 might throw errors when paired with newer versions. Try temporarily commenting out non-core third-party components to see if the error disappears—this will help you isolate the problematic package.
Last Resort: Migrate Code to a Fresh SDK 26 Project
If none of the above works, create a new Expo SDK 26 project with expo init (using the blank template), then gradually migrate your code files and dependencies into it. This helps rule out any hidden configuration corruption from the old project setup.
内容的提问来源于stack exchange,提问作者Marcos Martínez

