我想在React Native中使用本机代码构建项目,但是有问题。
我在https://facebook.github.io/react-native/docs/getting-started.html上使用了官方文档,但是在react-native run-android之后,我得到了一个错误
你能帮我吗?
The development server returned response error code: 500
URL: http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false
Body:
{"originModulePath":"D:\\Develop_Drafts\\projectname\\index.js","targetModuleName":"@babel/runtime/helpers/interopRequireDefault","message":"Unable to resolve module `@babel/runtime/helpers/interopRequireDefault` from `D:\\Develop_Drafts\\projectname\\index.js`: Module `@babel/runtime/helpers/interopRequireDefault` does not exist in the Haste module map\n\nThis might be related to https://github.com/facebook/react-native/issues/4968\nTo resolve try the following:\n 1. Clear watchman watches: `watchman watch-del-all`.\n 2. Delete the `node_modules` folder: `rm -rf node_modules && npm install`.\n 3. Reset Metro Bundler cache: `rm -rf /tmp/metro-bundler-cache-*` or `npm start -- --reset-cache`.\n 4. Remove haste cache: `rm -rf /tmp/haste-map-react-native-packager-*`.","errors":[{"description":"Unable to resolve module `@babel/runtime/helpers/interopRequireDefault` from `D:\\Develop_Drafts\\projectname\\index.js`: Module `@babel/runtime/helpers/interopRequireDefault` does not exist in the Haste module map\n\nThis might be related to https://github.com/facebook/react-native/issues/4968\nTo resolve try the following:\n 1. Clear watchman watches: `watchman watch-del-all`.\n 2. Delete the `node_modules` folder: `rm -rf node_modules && npm install`.\n 3. Reset Metro Bundler cache: `rm -rf /tmp/metro-bundler-cache-*` or `npm start -- --reset-cache`.\n 4. Remove haste cache: `rm -rf /tmp/haste-map-react-native-packager-*`."}],"name":"Error","stack":"Error: Unable to resolve module `@babel/runtime/helpers/interopRequireDefault` from `D:\\Develop_Drafts\\projectname\\index.js`: Module `@babel/runtime/helpers/interopRequireDefault` does not exist in the Haste module map\n\nThis might be related to https://github.com/facebook/react-native/issues/4968\nTo resolve try the following:\n 1. Clear watchman watches: `watchman watch-del-all`.\n 2. Delete the `node_modules` folder: `rm -rf node_modules && npm install`.\n 3. Reset Metro Bundler cache: `rm -rf /tmp/metro-bundler-cache-*` or `npm start -- --reset-cache`.\n 4. Remove haste cache: `rm -rf /tmp/haste-map-react-native-packager-*`.\n at ModuleResolver.resolveDependency (D:\\Develop_Drafts\\projectname\\node_modules\\metro\\src\\node-haste\\DependencyGraph\\ModuleResolution.js:209:1301)\n at ResolutionRequest.resolveDependency (D:\\Develop_Drafts\\projectname\\node_modules\\metro\\src\\node-haste\\DependencyGraph\\ResolutionRequest.js:83:16)\n at DependencyGraph.resolveDependency (D:\\Develop_Drafts\\projectname\\node_modules\\metro\\src\\node-haste\\DependencyGraph.js:238:485)\n at Object.resolve (D:\\Develop_Drafts\\projectname\\node_modules\\metro\\src\\lib\\transformHelpers.js:180:25)\n at dependencies.map.result (D:\\Develop_Drafts\\projectname\\node_modules\\metro\\src\\DeltaBundler\\traverseDependencies.js:311:29)\n at Array.map (<anonymous>)\n at resolveDependencies (D:\\Develop_Drafts\\projectname\\node_modules\\metro\\src\\DeltaBundler\\traverseDependencies.js:307:16)\n at D:\\Develop_Drafts\\projectname\\node_modules\\metro\\src\\DeltaBundler\\traverseDependencies.js:164:33\n at Generator.next (<anonymous>)\n at step (D:\\Develop_Drafts\\projectname\\node_modules\\metro\\src\\DeltaBundler\\traverseDependencies.js:266:307)"}
processBundleResult
BundleDownloader.java:296
access$200
BundleDownloader.java:37
onResponse
BundleDownloader.java:174
execute
RealCall.java:153
run
NamedRunnable.java:32
runWorker
ThreadPoolExecutor.java:1162
run
ThreadPoolExecutor.java:636
run
Thread.java:764
答案 0 :(得分:1)
尝试一下。
npm add @babel/runtime
npm install