node-gyp: Build error when run from npm script

Exit code: 1
Command: sh
Arguments: -c node-gyp rebuild
Directory: /Users/john/projects/photo-booth/app/node_modules/printer
Output:
gyp info it worked if it ends with ok
gyp info using node-gyp@3.6.1
gyp info using node@7.9.0 | darwin | x64
gyp WARN download NVM_NODEJS_ORG_MIRROR is deprecated and will be removed in node-gyp v4, please use NODEJS_ORG_MIRROR
gyp WARN download NVM_NODEJS_ORG_MIRROR is deprecated and will be removed in node-gyp v4, please use NODEJS_ORG_MIRROR
gyp info spawn /usr/local/bin/python2
gyp info spawn args [ '/Users/john/.nvm/versions/node/v7.9.0/lib/node_modules/node-gyp/gyp/gyp_main.py',
gyp info spawn args   'binding.gyp',
gyp info spawn args   '-f',
gyp info spawn args   'make',
gyp info spawn args   '-I',
gyp info spawn args   '/Users/john/projects/photo-booth/app/node_modules/printer/build/config.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/Users/john/.nvm/versions/node/v7.9.0/lib/node_modules/node-gyp/addon.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/Users/john/.node-gyp/7.9.0/include/node/common.gypi',
gyp info spawn args   '-Dlibrary=shared_library',
gyp info spawn args   '-Dvisibility=default',
gyp info spawn args   '-Dnode_root_dir=/Users/john/.node-gyp/7.9.0',
gyp info spawn args   '-Dnode_gyp_dir=/Users/john/.nvm/versions/node/v7.9.0/lib/node_modules/node-gyp',
gyp info spawn args   '-Dnode_lib_file=node.lib',
gyp info spawn args   '-Dmodule_root_dir=/Users/john/projects/photo-booth/app/node_modules/printer',
gyp info spawn args   '-Dnode_engine=v8',
gyp info spawn args   '--depth=.',
gyp info spawn args   '--no-parallel',
gyp info spawn args   '--generator-output',
gyp info spawn args   'build',
gyp info spawn args   '-Goutput_dir=.' ]
Traceback (most recent call last):
  File "/Users/john/.nvm/versions/node/v7.9.0/lib/node_modules/node-gyp/gyp/gyp_main.py", line 16, in <module>
    sys.exit(gyp.script_main())
  File "/Users/john/.nvm/versions/node/v7.9.0/lib/node_modules/node-gyp/gyp/pylib/gyp/__init__.py", line 545, in script_main
    return main(sys.argv[1:])
  File "/Users/john/.nvm/versions/node/v7.9.0/lib/node_modules/node-gyp/gyp/pylib/gyp/__init__.py", line 538, in main
    return gyp_main(args)
  File "/Users/john/.nvm/versions/node/v7.9.0/lib/node_modules/node-gyp/gyp/pylib/gyp/__init__.py", line 514, in gyp_main
    options.duplicate_basename_check)
  File "/Users/john/.nvm/versions/node/v7.9.0/lib/node_modules/node-gyp/gyp/pylib/gyp/__init__.py", line 130, in Load
    params['parallel'], params['root_targets'])
  File "/Users/john/.nvm/versions/node/v7.9.0/lib/node_modules/node-gyp/gyp/pylib/gyp/input.py", line 2778, in Load
    variables, includes, depth, check, True)
  File "/Users/john/.nvm/versions/node/v7.9.0/lib/node_modules/node-gyp/gyp/pylib/gyp/input.py", line 394, in LoadTargetBuildFile
    includes, True, check)
  File "/Users/john/.nvm/versions/node/v7.9.0/lib/node_modules/node-gyp/gyp/pylib/gyp/input.py", line 266, in LoadOneBuildFile
    aux_data, includes, check)
  File "/Users/john/.nvm/versions/node/v7.9.0/lib/node_modules/node-gyp/gyp/pylib/gyp/input.py", line 304, in LoadBuildFileIncludesIntoDict
    subdict_path, include)
  File "/Users/john/.nvm/versions/node/v7.9.0/lib/node_modules/node-gyp/gyp/pylib/gyp/input.py", line 2144, in MergeDicts
    MergeDicts(to[k], v, to_file, fro_file)
  File "/Users/john/.nvm/versions/node/v7.9.0/lib/node_modules/node-gyp/gyp/pylib/gyp/input.py", line 2137, in MergeDicts
    to[k] = MakePathRelative(to_file, fro_file, v)
  File "/Users/john/.nvm/versions/node/v7.9.0/lib/node_modules/node-gyp/gyp/pylib/gyp/input.py", line 2036, in MakePathRelative
    if item[-1] == '/':
IndexError: string index out of range while reading includes of binding.gyp while trying to load binding.gyp
gyp ERR! configure error 
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onCpExit (/Users/john/.nvm/versions/node/v7.9.0/lib/node_modules/node-gyp/lib/configure.js:336:16)
gyp ERR! stack     at emitTwo (events.js:106:13)
gyp ERR! stack     at ChildProcess.emit (events.js:194:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:215:12)
gyp ERR! System Darwin 16.6.0
gyp ERR! command "/Users/john/.nvm/versions/node/v7.9.0/bin/node" "/Users/john/.nvm/versions/node/v7.9.0/bin/node-gyp" "rebuild"
gyp ERR! cwd /Users/john/projects/photo-booth/app/node_modules/printer
gyp ERR! node -v v7.9.0
gyp ERR! node-gyp -v v3.6.1
gyp ERR! not ok

Environment: MacOS 10.12.5 Node 7.9.0 Python 2.7.13

When doing npm install node-gyp rebuild command fails with the above error. But when I run the same command directly in the node_modules/{module} directory it works. I checked it with other native modules, so it’s not related to the specific module. I also checked if python version used in the npm script run is the right one.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 17 (5 by maintainers)

Most upvoted comments

@jan-j you also have npm_config_scripts_prepend_node_path: '' in your environment (comes from npm config. You can check with npm config list)

@bnoordhuis maybe a quick release for that fix?

@refack Yes, I had, not sure how it got there. Builds fine after removing it. Thanks.