在运行 React Native 初始项目时,出现了 watchman.plist 权限被拒绝的问题。

8

我开始使用react-native,按照网站上的教程操作,但是在运行示例项目时,终端返回了一些错误信息:

Looking for JS files in
   /Users/username/Desktop/nativeTest/BookSearch 

[06:03:00] <START> Building Dependency Graph
[06:03:00] <START> Crawling File System
[06:03:00] <START> Loading bundles layout
[06:03:00] <END>   Loading bundles layout (0ms)

React packager ready.

2015-12-13T06:03:01,281: [cli] Failed to open /Users/username/Library/LaunchAgents/com.github.facebook.watchman.plist for write: Permission denied

2015-12-13T06:03:01,281: [cli] Failed to open /Users/username/Library/LaunchAgents/com.github.facebook.watchman.plist for write: Permission denied

Watchman:  watchman--no-pretty get-sockname returned with exit code null 2015-12-13T06:03:01,281: [cli] Failed to open /Users/username/Library/LaunchAgents/com.github.facebook.watchman.plist for write: Permission denied

 ERROR  watchman--no-pretty get-sockname returned with exit code null 2015-12-13T06:03:01,281: [cli] Failed to open /Users/username/Library/LaunchAgents/com.github.facebook.watchman.plist for write: Permission denied

Error: watchman--no-pretty get-sockname returned with exit code null 2015-12-13T06:03:01,281: [cli] Failed to open /Users/username/Library/LaunchAgents/com.github.facebook.watchman.plist for write: Permission denied

    at ChildProcess.<anonymous> (/Users/username/Desktop/nativeTest/BookSearch/node_modules/fb-watchman/index.js:194:18)
    at emitTwo (events.js:88:13)
    at ChildProcess.emit (events.js:173:7)
    at maybeClose (internal/child_process.js:819:16)
    at Socket.<anonymous> (internal/child_process.js:320:11)
    at emitOne (events.js:78:13)
    at Socket.emit (events.js:170:7)
    at Pipe._onclose (net.js:470:12)

See http://facebook.github.io/react-native/docs/troubleshooting.html
for common problems and solutions.
~
Process terminated. Press <enter> to close the window

我试图修改 com.github.facebook.watchman.plist 的文件权限,但实际上那里没有这个文件。也许我应该更改文件的路径?

我尝试过以下方法:

  1. brew update
  2. brew upgrade watchman
  3. brew uninstall watchman && brew install --HEAD watchman
  4. 重新启动并重新初始化项目

软件包版本(如果需要):

  1. node: v5.2.0
  2. watchman: v4.2.0
2个回答

22

当前用户没有对文件夹/Users/[用户名]/Library/LaunchAgents的权限。

使用以下命令来修复此问题:

$ sudo chown $(whoami) /Users/$(whoami)/Library/LaunchAgents

9

请确保/Users/username/Library/Users/username/Library/LaunchAgents的所有者是username并且具有正确的权限;以下是我的设置:

$ ls -ld ~/Library
drwx------+ 57 wez  users  1938 Nov  6 07:49 /Users/wez/Library
$ ls -ld ~/Library/LaunchAgents
drwxr-xr-x  3 wez  users  102 Dec 11 16:13 /Users/wez/Library/LaunchAgents
$ ls -l ~/Library/LaunchAgents/com.github.facebook.watchman.plist
-rw-r--r--  1 wez  users  1545 Dec 11 16:13 /Users/wez/Library/LaunchAgents/com.github.facebook.watchman.plist

请确保您不要以root或通过sudo运行watchman。

问题已解决,谢谢!我没有意识到在第一次运行watchman时会创建plist文件,而“~/Library/LaunchAgent”仍然归根所有。 - Kent Yang
我的情况不同。我该如何解决?$ ls -ld ~/Library/LaunchAgentslrwxr-xr-x 1 muhaimincs staff 46 Aug 16 11:03 /Users/muhaimincs/Library/LaunchAgents -> /usr/local/opt/mysql/homebrew.mxcl.mysql.plist - Muhaimin
这是我所错过的~/Library/LaunchAgents/com.github.facebook.watchman.plist。您可以在此处查看我的问题http://stackoverflow.com/questions/34912523/error-watchman-no-pretty-get-sockname-when-run-npm-start。 - Muhaimin
运行以下命令:$sudo chown <username> ~/Library/LaunchAgents - Jashan PJ

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