Nodejs express + jade html2jade

Nodejs express + jade html2jade

在mac os x 下安装html2jade 报错了

报错内容如下,有人碰到过嘛?

xcode-select: Error: No Xcode is selected. Use xcode-select -switch <path-to-xcode>, or see the xcode-select manpage (man xcode-select) for further information.

Traceback (most recent call last): File “/usr/local/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp”, line 18, in <module> sys.exit(gyp.main(sys.argv[1:])) File “/usr/local/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/init.py”, line 523, in main return gyp_main(args) File “/usr/local/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/init.py”, line 508, in gyp_main generator.GenerateOutput(flat_list, targets, data, params) File “/usr/local/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py”, line 2105, in GenerateOutput part_of_all=qualified_target in needed_targets) File “/usr/local/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py”, line 769, in Write self.Pchify)) File “/usr/local/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py”, line 1154, in WriteSources cflags = self.xcode_settings.GetCflags(configname) File “/usr/local/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation.py”, line 260, in GetCflags sdk_root = self._SdkPath() File “/usr/local/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation.py”, line 247, in _SdkPath return os.path.join(self._GetSdkBaseDir(), File “/usr/local/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation.py”, line 234, in _GetSdkBaseDir raise Exception(‘Error %d running xcode-select’ % job.returncode) Exception: Error 2 running xcode-select npm http 304 https://registry.npmjs.org/node

npm http 304 https://registry.npmjs.org/node-uuid npm http 304 https://registry.npmjs.org/hawk gyp ERR! configure error gyp ERR! stack Error: gyp failed with exit code: 1 gyp ERR! stack at ChildProcess.onCpExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:415:16) gyp ERR! stack at ChildProcess.EventEmitter.emit (events.js:98:17) gyp ERR! stack at Process.ChildProcess._handle.onexit (child_process.js:789:12) gyp ERR! System Darwin 12.4.1 gyp ERR! command “node” “/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js” "rebuild" gyp ERR! cwd /usr/local/lib/node_modules/html2jade/node_modules/jsdom/node_modules/contextify gyp ERR! node -v v0.10.12 gyp ERR! node-gyp -v v0.10.0 gyp ERR! not ok npm http 304 https://registry.npmjs.org/form-data/0.0.8 npm ERR! error rolling back Error


4 回复

Nodejs Express + Jade html2jade

在使用 Node.js 和 Express 框架时,有时我们需要将 HTML 文件转换为 Jade(现在称为 Pug)模板。这可以通过 html2jade 工具来实现。然而,在 Mac OS X 系统上安装 html2jade 时可能会遇到一些问题。例如,你可能会看到以下错误信息:

xcode-select: Error: No Xcode is selected. Use xcode-select -switch <path-to-xcode>, or see the xcode-select manpage (man xcode-select) for further information.

这个错误通常是因为系统没有正确配置 Xcode 命令行工具。以下是解决这个问题的步骤:

  1. 安装 Xcode 命令行工具: 打开终端并运行以下命令来安装 Xcode 命令行工具:

    xcode-select --install
    

    这将提示你下载并安装 Xcode 命令行工具。

  2. 设置 Xcode 命令行工具路径: 如果安装后仍然出现错误,可以手动设置 Xcode 命令行工具的路径:

    sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer
    
  3. 重新安装 html2jade: 安装完 Xcode 命令行工具后,重新安装 html2jade

    npm install -g html2jade
    

示例代码

假设你有一个简单的 HTML 文件 example.html

<!DOCTYPE html>
<html>
<head>
    <title>Example Page</title>
</head>
<body>
    <h1>Hello, World!</h1>
    <p>This is an example paragraph.</p>
</body>
</html>

你可以使用 html2jade 将其转换为 Jade 模板文件 example.jade

html2jade example.html

转换后的 example.jade 文件内容如下:

doctype html
html
  head
    title Example Page
  body
    h1 Hello, World!
    p This is an example paragraph.

总结

在 Mac OS X 上安装 html2jade 时遇到的错误通常是由于 Xcode 命令行工具未正确配置导致的。通过安装和配置 Xcode 命令行工具,可以顺利解决这个问题。此外,使用 html2jade 工具可以方便地将 HTML 文件转换为 Jade 模板文件,以便在 Node.js 和 Express 项目中使用。


我的node版本是 v0.10.12 python 版本是2.7.2

有人知道是哪里的问题吗??????

jade这么复杂的东西就不要用了,直接ejs把

根据你提供的错误信息,问题出在xcode-select命令上。你需要确保Xcode命令行工具已经正确安装并配置。你可以通过以下步骤解决这个问题:

  1. 安装Xcode命令行工具:

    xcode-select --install
    

    运行上述命令后,系统会提示你安装Xcode命令行工具。安装完成后,运行以下命令设置Xcode路径:

    sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer
    
  2. 尝试重新安装html2jade

    npm install -g html2jade
    

如果问题仍然存在,请检查你的Node.js和npm版本是否是最新的。你可以通过以下命令更新它们:

sudo npm install -g npm
sudo npm cache clean -f
sudo npm install -g n
sudo n stable

以上步骤应该能解决你在Mac OS X下安装html2jade时遇到的问题。

回到顶部