'npm install returns error. Showing "no such file directory ../node_modules/mongodb-client-encryption/deps/lib/...'

I have a pretty big NextJS project going on, using mongodb but I havent been able to run npm install on it as it gives the following error.

npm ERR! code 1
npm ERR! path <PATH TO PROJECT>/node_modules/mongodb-client-encryption
npm ERR! command failed
npm ERR! command sh -c prebuild-install --tag-prefix node-v || node-gyp rebuild
npm ERR! CXX(target) Release/obj.target/mongocrypt/src/mongocrypt.o
npm ERR!   SOLINK_MODULE(target) Release/mongocrypt.node
npm ERR! sh: <PATH TO PROJECT>/node_modules/.bin/prebuild-install: Permission denied
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using [email protected]
npm ERR! gyp info using [email protected] | darwin | x64
npm ERR! gyp info find Python using Python version 3.9.6 found at "/Library/Frameworks/Python.framework/Versions/3.9/bin/python3"
npm ERR! gyp info spawn /Library/Frameworks/Python.framework/Versions/3.9/bin/python3
npm ERR! gyp info spawn args [
npm ERR! gyp info spawn args   '<PATH TO PROJECT>/node_modules/node-gyp/gyp/gyp_main.py',
npm ERR! gyp info spawn args   'binding.gyp',
npm ERR! gyp info spawn args   '-f',
npm ERR! gyp info spawn args   'make',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '<PATH TO PROJECT>/node_modules/mongodb-client-encryption/build/config.gypi',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '<PATH TO PROJECT>/node_modules/node-gyp/addon.gypi',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '/Users/<MACOS USER NAME>/Library/Caches/node-gyp/16.13.1/include/node/common.gypi',
npm ERR! gyp info spawn args   '-Dlibrary=shared_library',
npm ERR! gyp info spawn args   '-Dvisibility=default',
npm ERR! gyp info spawn args   '-Dnode_root_dir=/Users/<MACOS USER NAME>/Library/Caches/node-gyp/16.13.1',
npm ERR! gyp info spawn args   '-Dnode_gyp_dir=<PATH TO PROJECT>/node_modules/node-gyp',
npm ERR! gyp info spawn args   '-Dnode_lib_file=/Users/<MACOS USER NAME>/Library/Caches/node-gyp/16.13.1/<(target_arch)/node.lib',
npm ERR! gyp info spawn args   '-Dmodule_root_dir=<PATH TO PROJECT>/node_modules/mongodb-client-encryption',
npm ERR! gyp info spawn args   '-Dnode_engine=v8',
npm ERR! gyp info spawn args   '--depth=.',
npm ERR! gyp info spawn args   '--no-parallel',
npm ERR! gyp info spawn args   '--generator-output',
npm ERR! gyp info spawn args   'build',
npm ERR! gyp info spawn args   '-Goutput_dir=.'
npm ERR! gyp info spawn args ]
npm ERR! gyp info spawn make
npm ERR! gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
npm ERR! ../src/mongocrypt.cc:33:13: warning: unused function 'StringFromBinary' [-Wunused-function]
npm ERR! std::string StringFromBinary(mongocrypt_binary_t* binary) {
npm ERR!             ^
npm ERR! ../src/mongocrypt.cc:68:17: warning: unused function 'BooleanOptionValue' [-Wunused-function]
npm ERR! NAN_INLINE bool BooleanOptionValue(v8::Local<v8::Object> options,
npm ERR!                 ^
npm ERR! 2 warnings generated.
npm ERR! clang: error: no such file or directory: '<PATH TO PROJECT>/node_modules/mongodb-client-encryption/deps/lib/libmongocrypt-static.a'
npm ERR! clang: error: no such file or directory: '<PATH TO PROJECT>/node_modules/mongodb-client-encryption/deps/lib/libkms_message-static.a'
npm ERR! clang: error: no such file or directory: '<PATH TO PROJECT>/

I have tried reinstalling node and npm. The offending package seems to be mongodb-client-encryption but I am not sure what about it is creating this error.

After this error occurs, I checked my files and there is no node_modules/mongodb-client-encryption directory being created.

I am running:

  • MacOS Monterey
  • npm -v 8.1.2
  • node -v v16.13.1

I know that there was a recent post (https://www.mongodb.com/community/forums/t/install-mongodb-client-encryption-on-mac-m1-node-16/125728) that had similar errors but the solutions outlined there have not worked. Could any one help me?



Solution 1:[1]

This one helped me and specifically this part from the blog:

I ran into an issue with libmongocrypt when I tried to run my code, because libmongocrypt was trying to statically link against libmongocrypt instead of dynamically linking. I have submitted an issue to the team to fix this issue, but to fix it, I had to run: export BUILD_TYPE=dynamic

So run this in the terminal before trying to npm install.

export BUILD_TYPE=dynamic

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 cigien