Skip to content

Commit 73cd050

Browse files
committed
fix: defensive autolocation of node-gyp in make-spawn-args
prevents runtime error in environments where `require.resolve` is not available Fall back to any existing `npm_config_node_gyp` provided by environment
1 parent 3552cd7 commit 73cd050

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

lib/make-spawn-args.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
/* eslint camelcase: "off" */
22
const setPATH = require('./set-path.js')
33
const { resolve } = require('path')
4-
const npm_config_node_gyp = require.resolve('node-gyp/bin/node-gyp.js')
4+
let npm_config_node_gyp
5+
if (typeof require === 'function' && typeof require.resolve === 'function') {
6+
npm_config_node_gyp = require.resolve('node-gyp/bin/node-gyp.js')
7+
}
58

69
const makeSpawnArgs = options => {
710
const {
@@ -23,8 +26,10 @@ const makeSpawnArgs = options => {
2326
npm_package_json: resolve(path, 'package.json'),
2427
npm_lifecycle_event: event,
2528
npm_lifecycle_script: cmd,
26-
npm_config_node_gyp,
2729
})
30+
if (typeof npm_config_node_gyp === 'string') {
31+
spawnEnv.npm_config_node_gyp = npm_config_node_gyp
32+
}
2833

2934
const spawnOpts = {
3035
env: spawnEnv,

0 commit comments

Comments
 (0)