我是新来的本地人。我想用反应导航创建一个项目。我收到此错误:
SyntaxError: Unexpected token in JSON at position 0
at JSON.parse (<anonymous>)
at FileStore.get(:\Users\fz\Documents\androidproject\test2\node_modules\metro-cache\src\stores\FileStore.js:26:19)
at C:\Users\fz\Documents\androidproject\test2\node_modules\metro-cache\src\Cache.js:76:40
at Generator.next (<anonymous>)
at step (C:\Users\fz\Documents\androidproject\test2\node_modules\metro-cache\src\Cache.js:18:30)
at C:\Users\fz\Documents\androidproject\test2\node_modules\metro-cache\src\Cache.js:37:14
at new Promise (<anonymous>)
at C:\Users\fz\Documents\androidproject\test2\node_modules\metro-cache\src\Cache.js:15:12
at Cache.get (C:\Users\fz\Documents\androidproject\test2\node_modules\metro-cache\src\Cache.js:102:7)
at C:\Users\fz\Documents\androidproject\test2\node_modules\metro\src\DeltaBundler\Transformer.js:166:34
这是我的app.js:
import React from 'react';
import Input from './input.js';
import Kalkulator from './kalkulator.js';
import { createBottomTabNavigator, createAppContainer } from 'react-
navigation'; // Version can be specified in package.json
const RootStack = createBottomTabNavigator({
Input: Input,
Kalkulator: Kalkulator
}
);
export default createAppContainer(RootStack);
这是我的package.json:
{
"name": "test2",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest",
"android-linux": "react-native bundle --platform android --dev false --
entry-file index.js --bundle-output
android/app/src/main/assets/index.android.bundle --assets-dest
android/app/src/main/res && react-native run-android"
},
"dependencies": {
"react": "16.6.3",
"react-native": "0.57.8",
"react-native-gesture-handler": "^1.0.12",
"react-navigation": "^3.0.9"
},
"devDependencies": {
"babel-jest": "23.6.0",
"jest": "23.6.0",
"metro-react-native-babel-preset": "0.51.1",
"react-test-renderer": "16.6.3"
},
"jest": {
"preset": "react-native"
}
}
我尝试在Google上进行搜索,但找不到解决此问题的方法,在构建此项目之前,我曾尝试在以前的项目中使用React导航,这很好,但是为什么现在出现此错误? >
答案 0 :(得分:2)
我今天陷入了同样的问题。我花了几个小时寻找解决方案。没事。 最后,我做了这样的事情:
尝试运行此命令-
npm start -- --reset-cache
在您的根项目目录中,此错误将得到解决。
此命令的目的是在重置缓存后启动npm。