我不需要react-native-fs
,应用会引发异常:
'main' has not been registered. This can happen if:
* Metro (the local dev server) is run from the wrong folder. Check if Metro is running, stop it and restart it in the current project.
* A module failed to load due to an error and `AppRegistry.registerComponent` wasn't called.
我按照官方文档中的指南进行安装。
App.js:
import React from 'react';
import { View } from 'react-native';
const RNFS = require("react-native-fs");
export default function App() {
return (
<View>
</View>
);
}
package.json:
{
"main": "index.js",
"scripts": {
"android": "react-native run-android",
"ios": "react-native run-ios",
"web": "expo start --web",
"start": "react-native start",
"test": "jest"
},
"dependencies": {
"expo": "~39.0.2",
"expo-splash-screen": "~0.6.0",
"expo-status-bar": "~1.0.2",
"expo-updates": "~0.3.2",
"react": "16.13.1",
"react-dom": "16.13.1",
"react-native": "~0.63.2",
"react-native-fs": "^2.16.6",
"react-native-gesture-handler": "~1.7.0",
"react-native-reanimated": "~1.13.0",
"react-native-screens": "~2.10.1",
"react-native-unimodules": "~0.11.0",
"react-native-web": "~0.13.12"
},
"devDependencies": {
"@babel/core": "~7.9.0",
"babel-jest": "~25.2.6",
"jest": "~25.2.6",
"react-test-renderer": "~16.13.1"
},
"jest": {
"preset": "react-native"
},
"private": true
}
很明显,如果我删除了require
行,则错误消失了。