问题描述
我正在尝试使用
创建 React-native 应用程序环境create-react-native-app confusion
但它并没有创建所有文件。它只在混淆文件夹中创建 package.json 和 yarn.lock,缺少 App.js,我收到了下面提到的错误。
Creating a new React Native app in E:\Developer's Area\ReactNative-Projects\confusion.
Using package manager as yarnpkg with yarn interface.
Installing packages. This might take a couple minutes.
Installing react-native-scripts...
yarn add v1.22.5
info No lockfile found.
[1/4] Resolving packages...
warning react-native-scripts > babel-runtime > [email protected]: core-js@<3 is no longer maintained and not recommended for usage due to the number of issues. Please,upgrade your dependencies to the actual version of core-js@3.
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Saved lockfile.
success Saved 20 new dependencies.
info Direct dependencies
└─ [email protected]
info All dependencies
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
└─ [email protected]
Done in 2.78s.
(node:9952) UnhandledPromiseRejectionWarning: Error: Cannot find module 'E:\Developer's Area\ReactNative-Projects\confusion\node_modules\react-native-scripts\build\scripts\init.js'
Require stack:
- C:\Users\sans\AppData\Local\Yarn\Data\global\node_modules\create-react-native-app\build\index.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:957:15)
at Function.Module._load (internal/modules/cjs/loader.js:840:27)
at Module.require (internal/modules/cjs/loader.js:1019:19)
at require (internal/modules/cjs/helpers.js:77:18)
at _callee2$ (C:\Users\sans\AppData\Local\Yarn\Data\global\node_modules\create-react-native-app\build\index.js:128:32)
at tryCatch (C:\Users\sans\AppData\Local\Yarn\Data\global\node_modules\regenerator-runtime\runtime.js:62:40)
at Generator.invoke [as _invoke] (C:\Users\sans\AppData\Local\Yarn\Data\global\node_modules\regenerator-runtime\runtime.js:296:22)
at Generator.prototype.<computed> [as next] (C:\Users\sans\AppData\Local\Yarn\Data\global\node_modules\regenerator-runtime\runtime.js:114:21)
at step (C:\Users\sans\AppData\Local\Yarn\Data\global\node_modules\babel-runtime\helpers\asyncToGenerator.js:17:30)
at C:\Users\sans\AppData\Local\Yarn\Data\global\node_modules\babel-runtime\helpers\asyncToGenerator.js:28:13
(node:9952) 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(). To terminate the node process on unhandled promise rejection,use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:9952) [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.
PS E:\Developer's Area\ReactNative-Projects>
这就是我设置应用程序的方式
yarn global add [email protected]
create-react-native-app confusion
yarn start
解决方法
[email protected] 不再支持,该版本是 4 年前发布的,最新版本是 3.5.3。您可以省略版本以获取最新版本 - yarn global add create-react-native-app
或使用 yarn create react-native-app
或 npx create-react-native-app
。
此外,如果您想创建一个托管 expo 项目,我建议您安装 expo-cli - npm i -g expo-cli
,然后运行 expo init
。 full installation docs here。