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

如何在不依赖额外包的情况下快速故意崩溃React Native应用?

Quick, Dependency-Free React Native Crash Code

Got it—you don't want to add extra packages, and exceptions are too slow or cause unwanted side effects. Here are a couple of no-fuss snippets that will crash your React Native app instantly, no external dependencies required:

This uses React Native's built-in ExceptionsManager module to trigger a native-level crash directly—no JS-level overhead, just an immediate app termination on both iOS and Android.

import { NativeModules } from 'react-native';

// Call this function whenever you need to crash the app
const crashApp = () => {
  NativeModules.ExceptionsManager.crash();
};

You can drop this into a component easily, like a test button:

import React from 'react';
import { View, Button, NativeModules } from 'react-native';

export default function CrashTestComponent() {
  return (
    <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
      <Button 
        title="Crash App" 
        onPress={() => NativeModules.ExceptionsManager.crash()} 
      />
    </View>
  );
}

This works in both development and production builds. Under the hood, it calls abort() on iOS and throws an uncaught RuntimeException on Android—super fast, no messy exception handling side effects.

2. JS-Level Fatal Crash

If you need a JS-only crash (though the native method is more reliable), this snippet will lock up the JS thread irreparably:

const crashJS = () => {
  // Create an object with a non-configurable getter that throws
  const fatalObj = Object.create(null);
  Object.defineProperty(fatalObj, 'crash', {
    get: () => { throw new Error('Fatal JS Crash'); },
    configurable: false
  });
  // Infinite loop accessing the getter to prevent recovery
  while (true) {
    const _ = fatalObj.crash;
  }
};

The native crash method is better for your use case though—faster, cleaner, and guarantees immediate app termination without hanging.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.12 04:57:57