8

Using this command: npm install jsdom, in an attempt to get jsdom up and running to use with a node.js server, I get the following series of errors. Could somebody please help clarify this issue? I think that there might also be an issue because it cannot install contextify...thanks in advance!

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
Apollo
  • 8,874
  • 32
  • 104
  • 192

3 Answers3

14

You need GCC to compile these node.js modules.

  1. Go to the App store and download the latest version of Xcode for free.
  2. Install Xcode (the app store actually downloads the "installer" for Xcode)
  3. Start Xcode
  4. Go to Preferences
  5. Go to Downloads
  6. Click on the "install" button after "Command Line Tools"
  7. Reboot

Done! :)

onlineracoon
  • 2,932
  • 5
  • 47
  • 66
  • Huh, I think that this worked, however I'm still receiving an error in my application that I'm trying to implement. I know this is out of the scope of this question and maybe I'll just ask another one, but do you have any idea what this error means? /Users/dereklo/Node/node_modules/jsdom/lib/jsdom.js:171 features = JSON.parse(JSON.stringify(window.document.implementation._fea ^ TypeError: Cannot read property 'implementation' of undefined – Apollo Jul 21 '12 at 16:37
  • Try to debug and see what "window.document" is containing, it doesn't contain anything at all ("undefined"), this is because "window.document" is clientside javascript? I don't know exactly what you are trying to do but window.document should be used @ clientside javascript not node.js. – onlineracoon Jul 21 '12 at 16:48
  • @Derek Go download and install Python (http://www.python.org/getit/mac/), after installation go to terminal and type "python" to see if it is triggering, if it isn't triggering you need to add Environment variables to make sure it is working. Reboot, retry to compile the Node.js module, finished :) – onlineracoon Jul 21 '12 at 16:53
  • In response to your first comment ^, I think you may have gotten my issue...I'm trying to pre-render some javascript server side (on node.js), turn that javascript into a png image (I'm creating a graph in javascript), and then pass that png image to the webpage being served up by node.js. Is this not allowed/do you have a better approach to this? – Apollo Jul 22 '12 at 03:40
  • p.s. python is installed as I'm using a mac – Apollo Jul 22 '12 at 03:40
1

After ensuring XCode Command Line Tools were installed I was still having issues with npm install jsdom. It turns out I was still running my node server so the install would fail. For anyone else that may come across this issue, be sure to Ctrl + C to stop your server then do npm install jsdom. Worked like a charm! :)

adamgedney
  • 81
  • 1
  • 10
0

The above didn't work for me (Node version 16.13.0 on Mac). I noticed part of the error node-pre-gyp WARN Pre-built binaries not installable for canvas@2.6.1 and node@16.13.0.

So I used Node version 14.18.2 (using NVM) instead which is fine in my case.
(I think that skips compiling and uses a prebuilt version.)

Then npm install worked as expected.

st_phan
  • 715
  • 9
  • 23