错误:在Windows中未找到Watchman的路径

3
我正在学习使用react-native编程来开发Android应用程序。在运行应用程序时,我遇到了一些错误unable to resolve module。我找到了一些相关链接,并建议运行此命令react-native start --reset-cache,该命令需要系统上安装watchman。我安装了watchman,但之后无法启动react-native
解决方法是执行以下命令:

react-native start

D:\React Native\Example 1\ExampleOne>react-native start
Scanning 560 folders for symlinks in D:\React Native\Example 1\ExampleOne\node_m
odules (27ms)
 ┌────────────────────────────────────────────────────────────────────────────┐

 │  Running packager on port 8081.                                            │

 │                                                                            │

 │  Keep this packager running while developing on any JS projects. Feel      │

 │  free to close this tab and run your own packager instance if you          │

 │  prefer.                                                                   │

 │                                                                            │

 │  https://github.com/facebook/react-native                                  │

 │                                                                            │

 └────────────────────────────────────────────────────────────────────────────┘

Looking for JS files in
   D:\React Native\Example 1\ExampleOne

Loading dependency graph...Watchman:  Watchman was not found in PATH.  See https
://facebook.github.io/watchman/docs/install.html for installation instructions

React packager ready.

jest-haste-map: Watchman crawl failed. Retrying once with node crawler.
  Usually this happens when watchman isn't running. Create an empty `.watchmanco
nfig` file in your project's root folder or initialize a git or hg repository in
 your project.
  Error: Watchman was not found in PATH.  See https://facebook.github.io/watchma
n/docs/install.html for installation instructions
Watchman:  Watchman was not found in PATH.  See https://facebook.github.io/watch
man/docs/install.html for installation instructions
 ERROR  Watchman was not found in PATH.  See https://facebook.github.io/watchman
/docs/install.html for installation instructions
{"code":"ENOENT","errno":"ENOENT","syscall":"spawn watchman","path":"watchman","
spawnargs":["--no-pretty","get-sockname"]}
Error: Watchman was not found in PATH.  See https://facebook.github.io/watchman/
docs/install.html for installation instructions
    at exports._errnoException (util.js:1022:11)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:193:32)
    at onErrorNT (internal/child_process.js:359:16)
    at _combinedTickCallback (internal/process/next_tick.js:74:11)
    at process._tickCallback (internal/process/next_tick.js:98:9)

See http://facebook.github.io/react-native/docs/troubleshooting.html
for common problems and solutions.

D:\React Native\Example 1\ExampleOne>

我已成功安装了watchman,但在尝试执行watchman命令时出现问题。这是我安装watchman的位置:D:\React Native\Example 1\ExampleOne\node_modules\watchman。我已将其添加到Windows机器的PATH中。但我不确定问题的根本原因是路径是否错误或我指向了错误的watchman目录?有人能告诉我如何解决这个问题吗?先感谢您了。以下是相关图片:

enter image description here

enter image description here

2个回答

1
通常这种情况发生在watchman没有运行的时候。在项目的根目录中创建一个空的.watchmanconfig文件,或者在项目中初始化git或hg存储库。
因此,您应该创建一个空的.watchmanconfig文件和/或使用npm install初始化文件夹。

1
您可以通过卸载watchman npm包来解决此问题。尝试全局和本地卸载npm uninstall -g watchmannpm uninstall watchman

嗨@TGMCians,这个解决方案使得'react-native start'能够运行了,但是当运行'react-native run-android'时,我遇到了一个错误,错误信息是:EPERM: 操作不允许...并且模拟器上显示了红色的错误屏幕,上面写着:无法获取BatchedBridge,请确保您的bundle正确打包。顺便说一下,我正在使用Windows 7系统,你有什么想法吗?谢谢! - VincentZHANG
感谢您的回复,TGMCians。虽然它没有解决问题,但是命令提示符中的错误消息已经消失了,唯一的问题是模拟器中的红屏幕仍然显示:“无法获取BatchedBridge,请确保您的捆绑包正确打包”,我在考虑是否应该重新安装watchman。您怎么看? - VincentZHANG
@VincentZHANG 是的 - Ajay S
谢谢@TGMCians,这又让cmd出现了错误,我回到了起点。 - VincentZHANG

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接