Skip to content

nodejs/npm: nodejs's util.h shadows util.h from the macOS sdk (breaks node-pty) #457238

@Mic92

Description

@Mic92

This affects basically any nodejs cli/tui application that are using node-pty i.e. qwen-code but also a bunch of others.

The error on macOS will look like this:

       > npm error + /nix/store/2b6ypynh4jz5r293psjg8dna9za6y5pv-clang-21.1.2/bin/clang++ @/nix/var/nix/builds/nix-71740-1699796910/cc-params.7F11G6
       > npm error ../src/unix/pty.cc:135:30: warning: missing field 'filter' initializer [-Wmissing-field-initializers]
       > npm error   135 |     struct kevent change = {0};
       > npm error       |                              ^
       > npm error ../src/unix/pty.cc:155:31: warning: missing field 'filter' initializer [-Wmissing-field-initializers]
       > npm error   155 |       struct kevent event = {0};
       > npm error       |                               ^
       > npm error ../src/unix/pty.cc:464:13: error: use of undeclared identifier 'openpty'
       > npm error   464 |   int ret = openpty(&master, &slave, nullptr, NULL, static_cast<winsize*>(&winp));
       > npm error       |             ^~~~~~~
       > npm error 2 warnings and 1 error generated.
       > npm error + /nix/store/xpxisjpwldh5f8y8xniizja9fxvbsqln-coreutils-9.8/bin/rm -f -- /nix/var/nix/builds/nix-71740-1699796910/cc-params.7F11G6
       > npm error make: *** [pty.target.mk:127: Release/obj.target/pty/src/unix/pty.o] Error 1
       > npm error gyp ERR! build error
       > npm error gyp ERR! stack Error: `make` failed with exit code: 2
       > npm error gyp ERR! stack at ChildProcess.<anonymous> (/nix/store/4whakvkkpcgbdzxl1y32vq7rb73k4faq-nodejs-22.20.0/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:219:23)
       > npm error gyp ERR! System Darwin 24.5.0
       > npm error gyp ERR! command "/nix/store/4whakvkkpcgbdzxl1y32vq7rb73k4faq-nodejs-22.20.0/bin/node" "/nix/store/4whakvkkpcgbdzxl1y32vq7rb73k4faq-nodejs-22.20.0/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
       > npm error gyp ERR! cwd /nix/var/nix/builds/nix-71740-1699796910/source/node_modules/node-pty
       > npm error gyp ERR! node -v v22.20.0
       > npm error gyp ERR! node-gyp -v v11.2.0
       > npm error gyp ERR! not ok
       > npm error Log files were not written due to an error writing to the directory: /nix/store/vdxf8waagjwrplv5a439dy2wb6zlrmw7-claude-code-ui-1.9.1-npm-deps/_logs
       > npm error You can rerun the command with `--loglevel=verbose` to see the logs in your terminal

The root cause is that the search path for the compiler looks something like this:

claude-code-ui> npm error #include <...> search starts here:
claude-code-ui> npm error  /nix/store/xfgxng2cagljj0klsd37f855b7h744ww-nodejs-22.20.0-source/src
claude-code-ui> npm error  /nix/store/xfgxng2cagljj0klsd37f855b7h744ww-nodejs-22.20.0-source/deps/openssl/config
claude-code-ui> npm error  /nix/store/xfgxng2cagljj0klsd37f855b7h744ww-nodejs-22.20.0-source/deps/openssl/openssl/include
claude-code-ui> npm error  /nix/store/xfgxng2cagljj0klsd37f855b7h744ww-nodejs-22.20.0-source/deps/uv/include
claude-code-ui> npm error  /nix/store/xfgxng2cagljj0klsd37f855b7h744ww-nodejs-22.20.0-source/deps/zlib
claude-code-ui> npm error  /nix/store/xfgxng2cagljj0klsd37f855b7h744ww-nodejs-22.20.0-source/deps/v8/include
claude-code-ui> npm error  ../node_modules/node-addon-api
claude-code-ui> npm error  /nix/store/245wgmjlkq2swfkb138xh1jvb41ag8mh-libcxx-19.1.2+apple-sdk-15.5/include
claude-code-ui> npm error  /nix/store/9y52z399adkbydgvmknv39rv60fh255f-compiler-rt-libc-21.1.2-dev/include
claude-code-ui> npm error  /nix/store/sj9axqq3f7lxqq9xal5k93h94pjd1wxs-libutil-72-dev/include
claude-code-ui> npm error  /nix/store/8ckn8ghxqbnd5z4c7ijsq7yps3ad1inj-nodejs-22.20.0-dev/include
claude-code-ui> npm error  /nix/store/4whakvkkpcgbdzxl1y32vq7rb73k4faq-nodejs-22.20.0/include
claude-code-ui> npm error  /nix/store/vrwl6j299frah1v6x3vmfjf1sr8x09la-libiconv-109-dev/include
claude-code-ui> npm error  /nix/store/7qls54r2f3yslz5hlhhcxpqzbg9fnr0a-libresolv-83-dev/include
claude-code-ui> npm error  /nix/store/v3y75iccd94qxzs6rng4axri35q2lyzx-libsbuf-14.1.0-dev/include
claude-code-ui> npm error  /nix/store/245wgmjlkq2swfkb138xh1jvb41ag8mh-libcxx-19.1.2+apple-sdk-15.5/include/c++/v1
claude-code-ui> npm error  /nix/store/xbi504848gn164lwzv2x2rclwvjxw7w1-clang-wrapper-21.1.2/resource-root/include
claude-code-ui> npm error  /nix/store/ybygcq3s191f07bwgxbqpgqv0ak4h17k-apple-sdk-11.3/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include
claude-code-ui> npm error  /nix/store/ybygcq3s191f07bwgxbqpgqv0ak4h17k-apple-sdk-11.3/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks (framework directory)
claude-code-ui> npm error  /nix/store/73sxxnqav6hm0i58canf23fqpl1qmbpk-libSystem-B/include

when the compiler that looks for util.h it will find this:

% ls -la /nix/store/xfgxng2cagljj0klsd37f855b7h744ww-nodejs-22.20.0-source/src/util.h
.r--r--r--@ 38k root 55 years  /nix/store/xfgxng2cagljj0klsd37f855b7h744ww-nodejs-22.20.0-source/src/util.h

However this file doesn't actually define the openpty() function instead it should find this:

% grep openpty /nix/store/ybygcq3s191f07bwgxbqpgqv0ak4h17k-apple-sdk-11.3/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/util.h
int     openpty(int *, int *, char *, struct termios *,

I haven't found yet a solution, but I thought I dump my analysis already because I encountered this now quite a few times.

Metadata

Metadata

Assignees

No one assigned

    Labels

    6.topic: darwinRunning or building packages on Darwin6.topic: nodejsNode.js is a free, open-source, cross-platform JavaScript runtime environment

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions