使用yarn使用create-react-native-app启动项目时出错

时间:2018-10-04 09:55:43

标签: react-native yarnpkg

我开始研究create-react-native-app。

使用“ sudo yarn global add create-react-native-app@1.0.0”和以下日志进行安装。

zadmin@zadmin-Vostro-3446:~$ sudo yarn global add create-react-native-app@1.0.0
[sudo] password for zadmin: 
yarn global v1.10.1
warning package.json: No license field
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...

success Installed "create-react-native-app@1.0.0" with binaries:
      - create-react-native-app
Done in 2.24s.

创建了一个子目录ReactNative,并通过以下日志在方便的位置开始搭建React Native应用程序:

zadmin@zadmin-Vostro-3446:~/Desktop/coursera$ cd ReactNative/
zadmin@zadmin-Vostro-3446:~/Desktop/coursera/ReactNative$ dir
zadmin@zadmin-Vostro-3446:~/Desktop/coursera/ReactNative$ create-react-native-app confusion
Creating a new React Native app in /home/zadmin/Desktop/coursera/ReactNative/confusion.

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

yarn add v1.10.1
warning ../../../../package.json: No license field
info No lockfile found.
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Saved lockfile.
success Saved 20 new dependencies.
info Direct dependencies
└─ react-native-scripts@2.0.1
info All dependencies
├─ ansi-styles@3.2.1
├─ babel-runtime@6.26.0
├─ chalk@2.4.1
├─ color-convert@1.9.3
├─ color-name@1.1.3
├─ core-js@2.5.7
├─ cross-spawn@5.1.0
├─ escape-string-regexp@1.0.5
├─ has-flag@3.0.0
├─ isexe@2.0.0
├─ lru-cache@4.1.3
├─ minimist@1.2.0
├─ pseudomap@1.0.2
├─ react-native-scripts@2.0.1
├─ regenerator-runtime@0.11.1
├─ shebang-command@1.2.0
├─ shebang-regex@1.0.0
├─ supports-color@5.5.0
├─ which@1.3.1
└─ yallist@2.1.2
Done in 2.98s.
(node:18277) UnhandledPromiseRejectionWarning: Error: Cannot find module '/home/zadmin/Desktop/coursera/ReactNative/confusion/node_modules/react-native-scripts/build/scripts/init.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)
    at Function.Module._load (internal/modules/cjs/loader.js:507:25)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at _callee2$ (/usr/local/share/.config/yarn/global/node_modules/create-react-native-app/build/index.js:128:32)
    at tryCatch (/usr/local/share/.config/yarn/global/node_modules/regenerator-runtime/runtime.js:62:40)
    at Generator.invoke [as _invoke] (/usr/local/share/.config/yarn/global/node_modules/regenerator-runtime/runtime.js:296:22)
    at Generator.prototype.(anonymous function) [as next] (/usr/local/share/.config/yarn/global/node_modules/regenerator-runtime/runtime.js:114:21)
    at step (/usr/local/share/.config/yarn/global/node_modules/babel-runtime/helpers/asyncToGenerator.js:17:30)
    at /usr/local/share/.config/yarn/global/node_modules/babel-runtime/helpers/asyncToGenerator.js:28:13
(node:18277) 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:18277) [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.

然后进入创建的应用程序,即混乱并尝试启动纱线,它不是从以下日志开始:

zadmin@zadmin-Vostro-3446:~/Desktop/coursera/ReactNative$ cd confusion/
zadmin@zadmin-Vostro-3446:~/Desktop/coursera/ReactNative/confusion$ yarn start
yarn run v1.10.1
warning ../../../../package.json: No license field
error Command "start" not found.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

请帮助我解决此问题!

1 个答案:

答案 0 :(得分:0)

根据https://github.com/react-community/create-react-native-app上的新文档,

  

注意:Create React Native App已与Expo CLI合并。   现在使用expo init来创建您的项目。请参阅世博会快速入门   有关使用Expo CLI入门的说明文档。

因此,您应该使用Expo CLI。您可以在https://github.com/react-community/create-react-native-app#quick-overview

找到快速入门

Installation Expo CLI指南