React-Native项目解决Xcode对真机编译报错:Can't find 'node' binary to build React Native bundle

刚开始接触React-Native的时候我曾遇到一个错,最近发现有人也在问这个问题,所以我在这里记一下,供同学参考

  • 开发React-Native项目需要搭建一系列开发环境,环境搭好之后,我在Xcode上编译的过程中遇到了一个错误:


    error
      error: Can't find 'node' binary to build React Native bundle
      If you have non-standard nodejs installation, select your project in Xcode,
      find 'Build Phases' - 'Bundle React Native code and images'
      and change NODE_BINARY to absolute path to your node executable
      (you can find it by invoking 'which node' in the terminal)
    
  • 一开始面对这个错误真的是束手无策,后来仔细阅读错误日志之后才发现自己是多么可笑,只能怪自己对英文不敏感,上边的错误日志翻译过来就是(我自己翻译的,大概就这么个意思,不喜勿喷):

      如果你使用了非标准的 nodejs 安装流程,
      在Xcode中选择Project -> Build Phases -> Bundle React Native code and images,
      把NODE_BINARY改为node可执行文件的绝对路径
      你可以在终端命令行中执行 `$ which node` 来查看你当前node的绝对路径
    
  • 好了,这下明白多了,我的nodejs是从官网下载的tar包解压手动安装的,所以export NODE_BINARY=node是不行的,需要换成node的绝对路径

      //终端执行
      $ which node    
      
      //输出node的绝对路径
    

    按照下图替换掉node

    Build Phases
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容