Npm install fails due to compilation error in node-gyp

I’m trying to deploy a small Node.js backend and I use (which uses msgpack) as part of the system. The build fails due to a compilation error in one of the packages being installed. (msgpack, error is in node-gyp)

npm ERR! code 1
npm ERR! path /opt/render/project/src/accit-server/node_modules/msgpack
npm ERR! command failed
npm ERR! command sh -c node-gyp rebuild
npm ERR! /opt/render/.cache/node-gyp/21.1.0/include/node/node.h:711:28: error: ‘std::string_view’ has not been declared
npm ERR!      Environment* env, std::string_view main_script_source_utf8);
npm ERR!                             ^~~~~~~~~~~
npm ERR! gyp ERR! build error 
npm ERR! gyp ERR! stack Error: `make` failed with exit code: 2
npm ERR! gyp ERR! stack     at ChildProcess.onExit (/opt/render/project/nodes/node-21.1.0/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:203:23)
npm ERR! gyp ERR! stack     at ChildProcess.emit (node:events:515:28)
npm ERR! gyp ERR! stack     at ChildProcess._handle.onexit (node:internal/child_process:294:12)
npm ERR! gyp ERR! System Linux 5.15.0-1053-aws
npm ERR! gyp ERR! command "/opt/render/project/nodes/node-21.1.0/bin/node" "/opt/render/project/nodes/node-21.1.0/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
npm ERR! gyp ERR! cwd /opt/render/project/src/accit-server/node_modules/msgpack
npm ERR! gyp ERR! node -v v21.1.0
npm ERR! gyp ERR! node-gyp -v v9.4.0
npm ERR! gyp ERR! not ok

The compilation for node-gyp is failing because something is configured incorrectly. I have Node.js version set to v21.6.2 and everything else is at the defaults.

Any help would be appreciated.

did you try setting the node version to match reported by gyp ERR, which is 21.1.0?
I don’t have experience with that particular package, but one package I did use that used node-gyp was really picky about matching node versions

Oh, I copied an old error message. I have it set to v21.6.2 and it still has the same error.

Somehow, I’ve fixed it?
I went and deleted package-lock.json and node_modules in my dev environment and then re-ran npm install, and that seems to have fixed the error on the deploy?

1 Like

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