无法使用“ create-react-native-app”创建新应用

时间:2018-09-28 07:01:26

标签: reactjs react-native terminal

直到现在,我一直没有遇到使用“ create-react-native-app” cli命令创建react-native应用程序的任何问题。它没有创建它创建的普通ios和android文件,而是仅创建了node_modules,package-lock.json和package.json文件。下面是我运行命令后返回的输出。

    $ create-react-native-app Rdx
Creating a new React Native app in /Users/apple/Documents/Vscode/Redux-Testing/Rdx.

Using package manager as npm with npm interface.
Installing packages. This might take a couple minutes.
Installing react-native-scripts...

npm notice created a lockfile as package-lock.json. You should commit this file.
+ react-native-scripts@2.0.1
added 20 packages in 19.223s
(node:73947) UnhandledPromiseRejectionWarning: Error: Cannot find module '/Users/apple/Documents/Vscode/Redux-Testing/Rdx/node_modules/react-native-scripts/build/scripts/init.js'
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.Module._load (module.js:474:25)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at _callee2$ (/Users/apple/npm/lib/node_modules/create-react-native-app/build/index.js:128:32)
    at tryCatch (/Users/apple/npm/lib/node_modules/create-react-native-app/node_modules/regenerator-runtime/runtime.js:62:40)
    at Generator.invoke [as _invoke] (/Users/apple/npm/lib/node_modules/create-react-native-app/node_modules/regenerator-runtime/runtime.js:296:22)
    at Generator.prototype.(anonymous function) [as next] (/Users/apple/npm/lib/node_modules/create-react-native-app/node_modules/regenerator-runtime/runtime.js:114:21)
    at step (/Users/apple/npm/lib/node_modules/create-react-native-app/node_modules/babel-runtime/helpers/asyncToGenerator.js:17:30)
    at /Users/apple/npm/lib/node_modules/create-react-native-app/node_modules/babel-runtime/helpers/asyncToGenerator.js:28:13
(node:73947) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:73947) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

在此先感谢您的支持!

2 个答案:

答案 0 :(得分:0)

这是因为react-native-scripts使用的create-react-native-app软件包较旧,现在您的create-react-native-app版本将是version: 1.0.0

更新程序包。

npm install -g create-react-native-app

现在create-react-native-app的版本将是2.0.2

您现在可以创建自己的应用了。

create-react-native-app Rdx

您可能会要求安装expo-cliY

create-react-native-app 2.0.2中的另一个好处是您可以创建blanktabs应用。使用箭头键在终端中选择您喜欢的应用。

答案 1 :(得分:0)

您使用的create-react-native-app版本很旧。它使用react-native-scripts代替Expo SDK。

您需要使用正确版本的react-native-scripts。您可以通过在使用create-react-native-app创建新项目时指定正确的react-native-script版本来做到这一点。要找到正确版本的react-native-scripts,请首先使用以下命令找出create-react-native-app的版本:

create-react-native-app --version

下一步,查看create-react-native-appreact-native-scripts的变更日志。

选择一个版本的react-native-scripts,它与您的create-react-native-apps版本大约同时发布。

然后,在使用create-react-native-app创建新项目时,指定react-native-scripts的版本。例如:

create-react-native-app --scripts-version 1.4.0 project-name