Description
Hi there,
I'm encountering a compilation error when attempting to install libpg-query-node
on macOS Sequoia 15.4. This issue appears to stem from a recent change in the macOS system headers, which now include the strchrnul
function, conflicting with the version defined within the library.
Below, I've outlined the details of the issue, including the environment, reproduction steps, error message, root cause, a suggested fix, a temporary workaround, and references to similar problems in other projects. I hope this information assists in resolving the issue. Please let me know if you need any additional details!
Environment
- macOS: Sequoia 15.4 (Build 24E248)
- Node.js: v22.13.1
- Yarn: v1.22.22
Steps to Reproduce
- Update your system to macOS Sequoia 15.4.
- Set up a new Node.js project or use an existing one that depends on
libpg-query
. - Run
yarn install
to trigger the installation and compilation process.
Error Message
During the build process with node-pre-gyp
, the following error occurs:
src/postgres/src_port_snprintf.c:374:1: error: static declaration of 'strchrnul' follows non-static declaration
374 | strchrnul(const char *s, int c)
| ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/_string.h:198:9: note: previous declaration is here
198 | strchrnul(const char *__s, int __c);
| ^
Cause of the Issue
The error arises from a conflict between the strchrnul
function now provided by macOS 15.4's system headers and the static implementation defined in libpg-query
. Prior to this macOS version, strchrnul
may not have been available in the system, prompting libraries to include their own versions. With Sequoia 15.4, the system's non-static declaration clashes with the library's static one, resulting in a redefinition error.
Proposed Solution
To address this, I suggest wrapping the library's strchrnul
definition in a conditional compilation directive to prevent redefinition when the system already provides it. Here's an example:
#ifndef HAVE_STRCHRNUL
static char *strchrnul(const char *s, int c)
{
// Function implementation
}
#endif
Additionally, the build configuration should define HAVE_STRCHRNUL
during compilation on systems like macOS 15.4 where strchrnul
is natively available. This approach ensures compatibility across different platforms.
Temporary Workaround
As a short-term fix, users can:
- Locate the file
node_modules/libpg-query/build/libpg_query/src/postgres/src_port_snprintf.c
. - Manually add the conditional directive (as shown above) around the
strchrnul
definition. - Rebuild the module by running:
node-pre-gyp build --fallback-to-build
This should allow the compilation to succeed locally until an official fix is released.
Related Issues
This problem isn't isolated to libpg-query-node
. Similar compilation errors due to strchrnul
conflicts have been reported in other projects on macOS 15.4, including:
These cases reinforce that the issue stems from the updated system headers in macOS Sequoia 15.4.
Additional Note
The root of this issue may lie in the upstream libpg_query
library, which libpg-query-node
depends on. For instance, a related problem was reported in sqlc-dev/sqlc Issue #3916 for pg_query_go
, another libpg_query
wrapper. It might be worth applying the fix in the libpg_query
repository first (e.g., at github.com/pganalyze/libpg_query) and then updating libpg-query-node
to use the patched version.
Thank you for taking the time to review this issue. I’m happy to assist further if needed and look forward to a resolution!
Activity
emieljanson commentedon Apr 9, 2025
Ran into this issue but the node_modules/libpg-query/build... isn't available as it isn't built yet. Haven't found a solution to install libpg-query on 15.4 yet.
strchrnul
Conflict pganalyze/libpg_query#282emieljanson commentedon Apr 9, 2025
It seems like the
libpg_query
already got fixed pganalyze/libpg_query#282 (comment)diego-coba commentedon Apr 14, 2025
Our team is facing this issue. As a workaround I had to run a Linux container and work on it using Remote Explorer in VSCode. We'd be really grateful for a new version released using the versión of libpg_query compatible with Mac Os 15.4
dallen4 commentedon Apr 23, 2025
we have a few devs blocked by this compilation/build step on a repo, any updates on when a new version of this library will be published?
Shahor commentedon May 7, 2025
Hi 👋🏽
Any updates on this?
borispetrovdev commentedon May 7, 2025
Upgrading
libpg_query
to version17
fixes this 👌Shahor commentedon May 7, 2025
Thank you @borispetrovdev
I was coming back to the issue to talk about this exactly.
Npm is a bit guilty of the situation here, even though I'm not sure what is happening.
If you look at the page for the project right now, here's what you (or at least I) would see:
But looking at the versions page specifically, there's indeed a version 17 available:
So I guess there's something that could be done here to avoid the confusion furthermore?
borispetrovdev commentedon May 7, 2025
Yes! This absolutely tripped me up and delayed my resolving of this problem by at least a couple of hours. I had no idea NPM had this quirk.
pyramation commentedon Jun 3, 2025
Yes, upgrade to 17! glad you found it :)