You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Native加载自定义组件时出现Error 500错误求助

解决Expo加载React Native应用时的Bundle return code: 500错误

嘿,作为React Native新手遇到这种打包错误确实让人头疼,我来帮你一步步排查解决!

首先看你提到的CustomButton.style.js代码片段:StyleSheet.creat...,这里大概率是拼写错误——StyleSheet.create()少写了最后一个字母e,这种语法错误会直接导致打包失败,返回500错误码。

具体解决步骤:

1. 修复样式文件的拼写错误

打开CustomButton.style.js,把StyleSheet.creat改成StyleSheet.create,完整的样式文件示例如下:

import { StyleSheet } from 'react-native';

export default StyleSheet.create({
  // 这里写你的样式规则
  buttonWrapper: {
    paddingVertical: 12,
    paddingHorizontal: 24,
    backgroundColor: '#007AFF',
    borderRadius: 8
  },
  buttonText: {
    color: '#fff',
    fontSize: 16,
    textAlign: 'center'
  }
});

2. 清除Expo缓存

有时候旧缓存会导致奇怪的打包异常,按以下步骤操作:

  • 关闭手机上的Expo客户端和电脑上的开发服务器
  • 在项目根目录运行命令:expo r -c(这个命令会重启开发服务器并清除缓存)
  • 重新扫码加载应用,看看错误是否消失

3. 检查组件的引入路径是否正确

确保在CustomButton.js里正确引入样式文件:

import React from 'react';
import { TouchableOpacity, Text } from 'react-native';
// 注意路径要和你的项目结构匹配
import styles from './CustomButton.style';

const CustomButton = ({ title, onPress }) => {
  return (
    <TouchableOpacity style={styles.buttonWrapper} onPress={onPress}>
      <Text style={styles.buttonText}>{title}</Text>
    </TouchableOpacity>
  );
};

export default CustomButton;

同时检查App.js中引入CustomButton的路径是否正确:

import CustomButton from './src/components/CustomButton';

4. 排查其他潜在语法错误

如果上面的步骤没解决问题,检查项目中其他文件是否存在以下问题:

  • 缺失分号、括号/引号不匹配
  • 组件导出/导入语句错误
  • 变量名拼写错误

额外建议

如果错误依然存在,可以尝试更新Expo CLI到最新版本:

npm install -g expo-cli

内容的提问来源于stack exchange,提问作者Mateus Antonio

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 04:00:39