如何运行React Native的现有项目

时间:2019-04-16 18:50:02

标签: javascript android windows react-native npm

我想下载并运行其他人的项目以考虑其功能。我遇到了很多问题...开始时并不容易,我只是不知道该怎么办,请帮忙

https://github.com/sunlight3d/react_native_v0.49/tree/master/61-Realm%20React%20Native%235.Filter%20data%20and%20working%20with%20To-Many%20Relationships/code/tutorialProject

1)复制到工作文件夹教程项目

2)打开VS代码

3)进入工作文件夹,然后在cmd文件夹教程项目中单击“打开”

4)然后我输入react-native run-android 并惨败

d:\JS\tutorialProject>react-native init tutorialProject
 internal/modules/cjs/loader.js:657 throw err; ^

 Error: Cannot find module 'graceful-fs' at
 Function.Module._resolveFilename
 (internal/modules/cjs/loader.js:655:15) at Function.Module._load
 (internal/modules/cjs/loader.js:580:25) at Module.require
 (internal/modules/cjs/loader.js:711:19) at require
 (internal/modules/cjs/helpers.js:14:16) at Object.<anonymous>
 (d:\JS\tutorialProject\node_modules\react-native\local-cli\cli.js:12:1)
 at Module._compile (internal/modules/cjs/loader.js:805:30) at
 Object.Module._extensions..js (internal/modules/cjs/loader.js:816:10)
 at Module.load (internal/modules/cjs/loader.js:672:32) at
 tryModuleLoad (internal/modules/cjs/loader.js:612:12) at
 Function.Module._load (internal/modules/cjs/loader.js:604:3)

我开始谷歌搜索,发现与某些依赖项有关。使用react-native init MyProject

5)react-native init tutorialProject并获得更紧的右线

我尝试通过npm启动服务器,这很有趣... 6)npm-intall

d:\JS\tutorialProject>npm install npm WARN deprecated core-js@1.2.7:
 core-js@<2.6.5 is no longer maintained. Please, upgrade to core-js@3
 or at least to actual version of core-js@2. npm WARN deprecated
 connect@2.30.2: connect 2.x series is deprecated npm ERR! path
 d:\JS\tutorialProject\node_modules\.bin\react-native npm ERR! code
 EEXIST npm ERR! Refusing to delete
 d:\JS\tutorialProject\node_modules\.bin\react-native: is outside
 d:\JS\tutorialProject\node_modules\react-native and not a link npm
 ERR! File exists: d:\JS\tutorialProject\node_modules\.bin\react-native
 npm ERR! Move it away, and try again.

 npm ERR! A complete log of this run can be found in: npm ERR!
 C:\Users\Nick\AppData\Roaming\npm-cache\_logs\2019-04-16T18_15_13_614Z-debug.log

在这里我绝对不知道。如何运行别人的项目?

7 个答案:

答案 0 :(得分:1)

下载后,需要将所有软件包安装在package.json

npm install --save

然后您需要启动另一个终端

npm start -- --reset-cache / npm start / react-native start 

用于启动捆绑器

最终您可以运行您的项目

react-native run-android 

答案 1 :(得分:0)

在安装了节点的计算机上,将命令行导航到项目文件夹的根目录。

然后安装依赖项:

npm i

这将安装项目需要构建的所有库

然后运行项目构建脚本。这在项目的package.json文件中定义。在这种情况下,该脚本称为启动。所以:

npm run start

答案 2 :(得分:0)

所有依赖项和插件均已在package.json文件中配置。所以您需要安装:

npm install

然后,您可以开始

react-native run-android

npm run start

答案 3 :(得分:0)

可能的答案:NPM, cannot find 'graceful-fs', no matter what I do 他遇到了同样的错误:找不到模块“ graceful-fs”

答案 4 :(得分:0)

如果您已经有捆绑应用(Android或ios ...)

react-native run-android / react-native run-ios 

否则,您应该运行

react-native start

然后运行:

react-native run-android (or ios)

答案 5 :(得分:0)

这是你在windows和android studio上编译时的答案

1.打开cmd(以管理员身份) 2. npm 安装 3.在Android studio中等待build gradle完成编译 4.在cmd上运行react-native android-run

有时您可能会收到此错误(请参阅下图)

这是由于 gradle 错误导致构建失败。要解决这个问题,您可以尝试删除错误消息中的文件/文件夹,然后再次运行 react-native android-run。

enter image description here

答案 6 :(得分:0)

就跑

  1. npm cache clean --force
  2. npm inpm install