React Native 项目

React Native 项目

我在创建新的 React Native 项目时遇到问题,当我运行

react-native init AwesomeApp

我得到的只是(package.json 和 yarn-error.log),命令中没有 iOS 或 Android 文件夹

This will walk you through creating a new React Native project in /Users/man/AwesomeApp
Using yarn v1.16.0
Installing react-native...
yarn add v1.16.0
error An unexpected error occurred: "/Users/man/package.json: Unexpected end of JSON input".
info If you think this is a bug, please open a bug report with the information provided in "/Users/man/AwesomeApp/yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.
Error: Command failed: yarn add react-native --exact
    at checkExecSyncError (child_process.js:616:11)
    at execSync (child_process.js:652:15)
    at run (/usr/local/lib/node_modules/react-native-cli/index.js:294:5)
    at createProject (/usr/local/lib/node_modules/react-native-cli/index.js:249:3)
    at init (/usr/local/lib/node_modules/react-native-cli/index.js:200:5)
    at Object.<anonymous> (/usr/local/lib/node_modules/react-native-cli/index.js:153:7)
    at Module._compile (internal/modules/cjs/loader.js:776:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
    at Module.load (internal/modules/cjs/loader.js:643:32)
    at Function.Module._load (internal/modules/cjs/loader.js:556:12) {
  status: 1,
  signal: null,
  output: [ null, null, null ],
  pid: 70691,
  stdout: null,
  stderr: null
}
Command `yarn add react-native --exact` failed.

我的堆栈是:

  • 节点:v12.5.0
  • npm: 6.10.0
  • 纱线:1.16.0
  • react-native-cli: 2.0.1
  • react-native:n/a – 不在 React Native 项目目录中

答案1

package.json您的主文件夹中有一个。这package.json似乎是无效的。

我建议您将其删除,因为它很可能不应该存在。

无论出于什么原因,Yarn 也会查看父package.json文件。

(另外建议您不要安装,react-native而是使用npx。)

答案2

npm install -g react-native-cli npm install

此命令将安装你的 iOS 和 Android 文件或节点模块

相关内容