mac 系统下 sublime text2 出现Node.js 路径问题 以及解决方案

mac系统下  

一般来说 我们默认安装的 node.js  都是存在/usr/local/bin/node中 

在Sublime的htmlprettify插件配置中 比如

{
  // Simply using `node` without specifying a path sometimes doesn't work :(
  // https://github.com/victorporof/Sublime-HTMLPrettify#oh-noez-command-not-found
  // http://nodejs.org/#download
  "node_path": {
    //"windows": "C:/Program Files/nodejs/node.exe",
    //"linux": "/usr/bin/nodejs",
    "osx": "/usr/local/bin/node"
  },
  // Automatically format when a file is saved.
  "format_on_save": false,

  // Only format the selection if there's one available.
  "format_selection_only": true,

  // Log the settings passed to the prettifier from `.jsbeautifyrc`.
  "print_diagnostics": true
}

1.在命令行中 运行node -v  确定 node已经安装成功,


2.在命令行中 运行 which node  找到  node的所在目录是不是和配置的一样,如果不一样则修改 配置文件中的路径为 which node 告知我们的目录


3.但是我们执行 prettycode(shift+comand+H)的时候还是会出现  

Node.js was not found in the default path. Please specify the location.


4.有兴趣的同学可以通过ctr+`去看Sublime 的运行日志 里面会提及到 

Unexpected error(<type 'exceptions.UnicodeEncodeError'>): 'ascii' codec can't encode characters in position 272-273: ordinal not in range(128)
Traceback (most recent call last):
  File "./sublime_plugin.py", line 362, in run_
  File "./HTMLPrettify.py", line 48, in run
  File "./HTMLPrettify.py", line 124, in get_output_diagnostics
AttributeError: 'NoneType' object has no attribute 'find'

  我们可以看得出来这个报错信息和 HTMLprettify.py有关系.(没兴趣的同学可以不用管这个)


5.根据github 上得高人指出  这个是解码问题 Sublime 这个插件不支持 utf-8 硬解  那么我们给他加encode("utf-8")便可

所以我们直接去修改 HTMLprettify.py(记得先备份源文件)

(1)找到HTMLprettify.py      一般都在  /Users/adfinitas42/Library/Application Support/Sublime Text 2/Packages/Sublime-HTMLPrettify/HTMLPrettify.py


(2) 84 行修改: PluginUtils.get_node_path() 成为PluginUtils.get_node_path().encode("utf-8")


(3)86行 修改 file_path = self.view.file_name()成为为 tfile_path = self.view.file_name().encode("utf-8")

 到此 问题就能解决(我的是mac 10.9.5  其他的没测试过)



顺便附上

github 讨论地址https://github.com/victorporof/Sublime-HTMLPrettify/issues/107



转载于:https://my.oschina.net/u/1040928/blog/404391

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值