我不断收到此错误:
Disconnected from the Metro server.
at node_modules\react-native\Libraries\LogBox\LogBox.js:117:10 in registerWarning
at node_modules\react-native\Libraries\LogBox\LogBox.js:63:8 in warnImpl
at node_modules\react-native\Libraries\LogBox\LogBox.js:36:4 in console.warn
at node_modules\expo\build\environment\react-native-logs.fx.js:18:4 in warn
at node_modules\react-native\Libraries\Utilities\HMRClient.js:260:4 in setHMRUnavailableReason
at node_modules\react-native\Libraries\Utilities\HMRClient.js:234:29 in client.on$argument_1
at node_modules\eventemitter3\index.js:180:21 in emit
at node_modules\metro\src\lib\bundle-modules\HMRClient.js:118:6 in _ws.onclose
at node_modules\event-target-shim\dist\event-target-shim.js:818:20 in EventTarget.prototype.dispatchEvent
at node_modules\react-native\Libraries\WebSocket\WebSocket.js:246:8 in _eventEmitter.addListener$argument_1
at node_modules\react-native\Libraries\vendor\emitter\EventEmitter.js:189:10 in emit
at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:416:4 in __callFunction
at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:109:6 in __guard$argument_0
at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:364:10 in __guard
at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:108:4 in callFunctionReturnFlushedQueue
at [native code]:null in callFunctionReturnFlushedQueue
我正在使用 React Native Expo,出于某种原因,这发生在 fetch
请求或共享文件之后。它仅在我执行此 function
之后或时发生。这是function
:
const exportReport = async () => {
if (validate()) {
setLoading(true);
let token = await SecureStore.getItemAsync("token");
return await fetch("https://notarealapi.herokuapp.com/api/export", {
method: "POST",
headers: {
"content-type": "application/json",
Authorization: `JWT ${JSON.parse(token)}`,
},
body: JSON.stringify({ note: note, mission: value }),
})
.then((res) => res.json())
.then(async (json) => {
if (json.hasOwnProperty("msg")) {
Alert.alert(json.msg);
} else {
setLoading(false);
console.log(json);
const reportUrl = "data:application/pdf;base64," + String(json.pdf);
console.log(reportUrl);
const base64Code = reportUrl.split(
"data:application/pdf;base64,"
)[1];
const filename = FileSystem.documentDirectory + "report.pdf";
console.log(base64Code);
await FileSystem.writeAsStringAsync(filename, base64Code, {
encoding: FileSystem.EncodingType.Base64,
});
const _mediaResult = await MediaLibrary.saveToLibraryAsync(
filename
);
await Sharing.shareAsync(filename);
}
})
.catch((error) => console.error(error));
}
};
另外,我认为这个错误与Logbox有关,但除此之外,我一无所知。
错误只发生在这个函数中。