Issues with npm Package Installation on macOS

I’m encountering an error when trying to install packages for my Node.js application on macOS.

While executing the installation command, it fetches the packages without issue, but fails during the compilation phase. The failure occurs specifically with a package called [email protected] that requires native code to be compiled.

This is the primary error message that appears:

npm ERR! error installing [email protected]

The complete output indicates:

myuser$ npm install
npm http GET https://registry.npmjs.org/lodash
npm http 304 https://registry.npmjs.org/lodash
npm http GET https://registry.npmjs.org/cheerio
npm http GET https://registry.npmjs.org/xml-parser
npm http 304 https://registry.npmjs.org/xml-parser
npm WARN [email protected] package.json: repository['web'] should probably be repository['url']
npm http 304 https://registry.npmjs.org/cheerio
npm http GET https://registry.npmjs.org/css-select
npm http GET https://registry.npmjs.org/webview-context
npm http 304 https://registry.npmjs.org/css-select
npm http 304 https://registry.npmjs.org/webview-context

> [email protected] preinstall /Users/myuser/Projects/music-app/node_modules/lodash/node_modules/cheerio/node_modules/webview-context
> node-gyp clean || (exit 0); node-gyp configure build

Nothing to clean (project not configured)
Setting srcdir to                        : /Users/myuser/Projects/music-app/node_modules/lodash/node_modules/cheerio/node_modules/webview-context
Setting blddir to                        : /Users/myuser/Projects/music-app/node_modules/lodash/node_modules/cheerio/node_modules/webview-context/build
Checking for program g++ or c++          : not found
/Users/myuser/Projects/music-app/node_modules/lodash/node_modules/cheerio/node_modules/webview-context/binding.gyp:8: error: could not configure a cxx compiler!
npm ERR! error installing [email protected]
npm ERR! error installing [email protected]
npm ERR! error installing [email protected]
npm ERR! [email protected] preinstall: `node-gyp clean || (exit 0); node-gyp configure build`
npm ERR! `sh "-c" "node-gyp clean || (exit 0); node-gyp configure build"` failed with 1
npm ERR!
npm ERR! Failed at the [email protected] preinstall script.
npm ERR! This is most likely a problem with the webview-context package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-gyp clean || (exit 0); node-gyp configure build
npm ERR! You can get their info via:
npm ERR!     npm owner ls webview-context
npm ERR! There is likely additional logging output above.
npm ERR!
npm ERR! System Darwin 11.2.0
npm ERR! command "node" "/usr/local/bin/npm" "install"
npm ERR! cwd /Users/myuser/Projects/music-app
npm ERR! node -v v0.8.12
npm ERR! npm -v 1.2.14
npm ERR! code ELIFECYCLE
npm ERR! message [email protected] preinstall: `node-gyp clean || (exit 0); node-gyp configure build`
npm ERR! message `sh "-c" "node-gyp clean || (exit 0); node-gyp configure build"` failed with 1
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR!     /Users/myuser/Projects/music-app/npm-debug.log
npm not ok

I am using macOS with Xcode installed. Many solutions I found are catered towards Windows, but I need assistance specific to macOS. Could anyone provide suggestions for resolving this issue?

This fails because node-gyp can’t find the build tools, even with Xcode installed. The error shows it’s looking for g++ or c++ compilers that aren’t in your PATH. Installing Command Line Tools might not be enough - you may need to link them manually if you’ve upgraded macOS recently. After xcode-select --install, run sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer to fix the toolchain reference. I’ve seen webview-context cause problems on certain Node versions. You’re running Node 0.8.12 which is ancient - update to something recent first. Most native modules don’t support old Node versions anymore, and newer releases handle gyp compilation way better. If it’s still broken after fixing the compiler issue, look for an alternative package or newer version that doesn’t need native compilation.

You’re missing the C++ compiler tools that node-gyp needs to build native modules. The dead giveaway is that “Checking for program g++ or c++: not found” message in your output.

Having Xcode installed isn’t enough - you need the Command Line Tools too. Run xcode-select --install in your terminal to get g++ and make.

Once that’s done, check if it worked with g++ --version. If you see version info, clear your npm cache with npm cache clean, delete node_modules, and try installing again.

I hit this exact same issue setting up an old project on a new Mac. Installing Command Line Tools fixed it right away, even though I already had Xcode.

Had the exact same issue! Node 0.8.12 is ancient - we’re talking 2012 here. That webview-context package likely dropped support for old Node versions ages ago. Update Node first before touching Xcode - it’ll probably fix everything. Also worth checking if you even need webview-context or if there’s something newer you can use instead.

This topic was automatically closed 4 days after the last reply. New replies are no longer allowed.