问题在Mac上安装JSDOM

使用这个命令:npm install jsdom,试图让jsdom运行并与node.js服务器一起使用,我得到以下一系列错误。 有人请帮助澄清这个问题? 我认为可能还有一个问题,因为它不能安装contextify …提前感谢!

npm http GET https://registry.npmjs.org/jsdom npm http 304 https://registry.npmjs.org/jsdom npm http GET https://registry.npmjs.org/htmlparser npm http GET https://registry.npmjs.org/cssom npm http GET https://registry.npmjs.org/contextify npm http 304 https://registry.npmjs.org/contextify npm http 304 https://registry.npmjs.org/cssom npm http 304 https://registry.npmjs.org/htmlparser npm WARN package.json cssom@0.2.5 No README.md file found! npm http GET https://registry.npmjs.org/bindings npm http 304 https://registry.npmjs.org/bindings > contextify@0.1.3 install /Users/dereklo/node_modules/jsdom/node_modules/contextify > node-gyp rebuild gyp ERR! rebuild error Error: not found: make gyp ERR! rebuild error at F (/usr/local/lib/node_modules/npm/node_modules/which/which.js:43:28) gyp ERR! rebuild error at E (/usr/local/lib/node_modules/npm/node_modules/which/which.js:46:29) gyp ERR! rebuild error at /usr/local/lib/node_modules/npm/node_modules/which/which.js:57:16 gyp ERR! rebuild error at Object.oncomplete (fs.js:297:15) gyp ERR! not ok npm WARN optional dep failed, continuing contextify@0.1.3 jsdom@0.2.15 node_modules/jsdom ├── cssom@0.2.5 └── htmlparser@1.7.6 

你需要GCC编译这些node.js模块。

  1. 转到app store,免费下载最新版本的Xcode。
  2. 安装Xcode(app store实际上下载Xcode的“安装程序”)
  3. 启动Xcode
  4. 转到首选项
  5. 转到下载
  6. 点击“安装”button后,“命令行工具”
  7. 重启

完成! 🙂

确保安装了XCode命令行工具之后,我仍然遇到了npm install jsdom问题。 事实certificate,我仍在运行我的节点服务器,所以安装将失败。 对于任何可能遇到此问题的人,请务必按Ctrl + C来停止您的服务器,然后执行npm install jsdom 。 像魅力一样工作! 🙂