首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >HostFunction中的异常:来自JS的格式错误的调用:字段大小不同--问题发生在实际设备上,而不是模拟器上。

HostFunction中的异常:来自JS的格式错误的调用:字段大小不同--问题发生在实际设备上,而不是模拟器上。
EN

Stack Overflow用户
提问于 2020-02-04 16:28:09
回答 1查看 2.6K关注 0票数 0

在“世博/反应本地项目”中的一系列代码行之后,我想在我的iPhone上测试它。第一分钟进行得很顺利,直到我收到一条意外的错误消息:

错误:HostFunction中的异常: JS:字段大小不同的格式错误调用。

开发过程中发生了几次错误,因为我意外地将一个NaN存储在某个地方。到目前为止,很好,很高兴错误信息直接来了,我知道从哪里开始摆脱它。

以下是错误:

代码语言:javascript
运行
复制
[Unhandled promise rejection: Error: Exception in HostFunction: Malformed calls from JS: field sizes are different.]
Stack trace:
  node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:271:39 in enqueueNativeCall
  node_modules/react-native/Libraries/BatchedBridge/NativeModules.js:137:8 in fn
  node_modules/react-native/Libraries/Core/Timers/JSTimers.js:259:23 in setTimeout
  node_modules/promise/setimmediate/rejection-tracking.js:47:10 in <unknown>
  node_modules/promise/setimmediate/core.js:169:16 in reject
  node_modules/promise/setimmediate/core.js:211:11 in doResolve
  node_modules/promise/setimmediate/core.js:66:12 in Promise
  node_modules/react-native/Libraries/BatchedBridge/NativeModules.js:98:25 in fn
  node_modules/@unimodules/react-native-adapter/build/NativeModulesProxy.js:15:52 in _callee$
  node_modules/regenerator-runtime/runtime.js:45:44 in tryCatch
  node_modules/regenerator-runtime/runtime.js:271:30 in invoke
  node_modules/regenerator-runtime/runtime.js:45:44 in tryCatch
  node_modules/regenerator-runtime/runtime.js:135:28 in invoke
  node_modules/regenerator-runtime/runtime.js:170:17 in <unknown>
  node_modules/promise/setimmediate/core.js:45:7 in tryCallTwo
  node_modules/promise/setimmediate/core.js:200:23 in doResolve
  node_modules/promise/setimmediate/core.js:66:12 in Promise
  node_modules/regenerator-runtime/runtime.js:169:27 in callInvokeWithMethodAndArg
  node_modules/regenerator-runtime/runtime.js:192:38 in enqueue
  node_modules/regenerator-runtime/runtime.js:216:8 in <unknown>
  node_modules/@unimodules/react-native-adapter/build/NativeModulesProxy.js:10:62 in _callee
  node_modules/expo-file-system/build/FileSystem.js:50:55 in writeAsStringAsync$
  node_modules/regenerator-runtime/runtime.js:45:44 in tryCatch
  node_modules/regenerator-runtime/runtime.js:271:30 in invoke
  node_modules/regenerator-runtime/runtime.js:45:44 in tryCatch
  node_modules/regenerator-runtime/runtime.js:135:28 in invoke
  node_modules/regenerator-runtime/runtime.js:170:17 in <unknown>
  node_modules/promise/setimmediate/core.js:45:7 in tryCallTwo
  node_modules/promise/setimmediate/core.js:200:23 in doResolve
  node_modules/promise/setimmediate/core.js:66:12 in Promise
  node_modules/regenerator-runtime/runtime.js:169:27 in callInvokeWithMethodAndArg
  node_modules/regenerator-runtime/runtime.js:192:38 in enqueue
  node_modules/regenerator-runtime/runtime.js:216:8 in <unknown>
  node_modules/expo-file-system/build/FileSystem.js:46:7 in writeAsStringAsync
  node_modules/redux-persist-expo-filesystem/index.js:13:34 in writeFile
  node_modules/redux-persist-expo-filesystem/index.js:26:30 in <unknown>
  node_modules/promise/setimmediate/core.js:37:14 in tryCallOne
  node_modules/promise/setimmediate/core.js:123:25 in <unknown>
  node_modules/react-native/Libraries/Core/Timers/JSTimers.js:152:14 in _callTimer
  node_modules/react-native/Libraries/Core/Timers/JSTimers.js:200:17 in _callImmediatesPass
  node_modules/react-native/Libraries/Core/Timers/JSTimers.js:473:30 in callImmediates
  node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:337:6 in __callImmediates
  node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:135:6 in <unknown>
  node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:314:10 in __guard
  node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:134:17 in flushedQueue

在多次启动应用程序之后,错误会更频繁地发生,使用几秒钟后就会发生错误。还原持久化存储是主要问题。我无法解释为什么它在模拟器上工作得很好(而且现在仍然工作得很好),而在一个真正的设备上却没有。

我尝试了多个存储包,如‘redux-持久化-expo-fs-存储’,‘redux-持久化/lib/存储’和‘redux-持久化-expo-文件系统’。他们中没有一个人做过这项工作。

redux/index.js文件:

代码语言:javascript
运行
复制
import { combineReducers, createStore, applyMiddleware } from 'redux';
import promiseMiddleware from 'redux-promise-middleware';
import { persistStore, persistReducer } from 'redux-persist';
import guidelines from './guidelines/reducers';
import global from './global/reducers';
import ExpoFileSystemStorage from 'redux-persist-expo-filesystem';
import { composeWithDevTools } from 'redux-devtools-extension';
const persistConfig = {
    key: 'root',
    keyPrefix:'',
    storage: ExpoFileSystemStorage,
    timeout: null
}
const reducers = combineReducers({
    global,
    guidelines,
})
const persistedReducer = persistReducer(persistConfig, reducers);
export const store = createStore(persistedReducer, composeWithDevTools(applyMiddleware(promiseMiddleware())));
export const persistor = persistStore(store);

函数promiseMiddleware用于处理redux中的异步操作创建者,如下所示,axios用于检索actions.js中的数据:

代码语言:javascript
运行
复制
import axios from 'axios';
...
export const FETCH_AVAILABLE_GUIDELINES = 'FETCH_AVAILABLE_GUIDELINES';
export const FETCH_AVAILABLE_GUIDELINES_PENDING = 'FETCH_AVAILABLE_GUIDELINES_PENDING';
export const FETCH_AVAILABLE_GUIDELINES_FULFILLED = 'FETCH_AVAILABLE_GUIDELINES_FULFILLED';
export const FETCH_AVAILABLE_GUIDELINES_REJECTED = 'FETCH_AVAILABLE_GUIDELINES_REJECTED';
export const fetchAvailableGuidelines = () => {
    return {
        type: FETCH_AVAILABLE_GUIDELINES,
        payload: axios.get(CONFIG.API.ROOT + CONFIG.API.PATHS.OVERVIEW),
    }
};
...

reducers.js

代码语言:javascript
运行
复制
import { FETCH_AVAILABLE_GUIDELINES_FULFILLED } from './actions'
const initialState = () => {
    return {
        availableGuidelines: [],
        ...
    }
}
export default (state = initialState, action) => {
    switch(action.type) {
        case FETCH_AVAILABLE_GUIDELINES_FULFILLED:
             return {
                 ...state,
                 availableGuidelines: [...action.payload.data],
             }
        ...
    }
}

是否有人有同样的问题或提示如何调试我的redux持久化存储。存储的数据是一个大型JSON对象。我确信所有的键都有有效值。

谢谢你的建议和帮助。

编辑:我的指导原则是6MB左右。如果我只取一个,它似乎不会崩溃。一旦下载了多个指南,它就会崩溃。我相信这和存储系统有关。

代码语言:javascript
运行
复制
expo: 35.0
redux: ^4.0.1
redux-persist: ^5.10.0
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-02-17 19:29:32

如果您在每个应用程序启动时都获取这些数据,并且不关心这些数据是否脱机保存,我建议使用redux-persistredux-persist配置将如此大的状态从持久化中列入黑名单。

如果这种状态是静态的,并且没有变化,那么您也可以将它写入一个JSON文件并使用该文件作为数据源。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60061678

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档