Building application with @liskhq/lisk-cryptography breaks CI/CD pipeline

I am building an application that uses @liskhq/lisk-cryptography in a Gitlab CI/CD pipeline. There are multiple stages with a ‘npm install’ stage and a ‘deploy’ stage. node_modules and other files are cached between those stages and this is where my problem starts.

The cryptography package has an optional dependency ‘sodium-native’ that creates a static link with the libsodium when you run npm install. Caching those modules breaks that link between sodium package and native libsodium executable. The pipeline fails with following message: ENOENT: no such file or directory: /node_modules/@liskhq/lisk-cryptography/node_modules/sodium-native/tmp/lib/

The sodium-native is marked as an optional dependency so my solution was to change the command ‘npm install’ to ‘npm install --no-optional’. The flag will not include the dependency on the installation phase.

The creation of this link does not happen on every OS. My local machine (MacOS) has no issues while building with linux alpine images does have this problem.

Better solutions or any input is always welcome