aws / aws-lambda-nodejs-runtime-interface-client

Apache License 2.0
177 stars 57 forks source link

Inability to install `aws-lambda-ric` on MacOS(Darwin) #78

Closed alvis closed 9 months ago

alvis commented 10 months ago

This is an intriguing issue with the install script missing in package.json in combination with binding.gyp on the root.

According to npm documentation, and a equivalent implementation on pnpm

If there is a binding.gyp file in the root of your package and you haven't defined your own install or preinstall scripts, npm will default the install command to compile using node-gyp via node-gyp rebuild

So on a Darwin machine, upon installation of aws-lambda-ric, the package manage will always run three life cycle scripts

  1. preinstall
  2. install (implied from the existence of binding.gyp and a missing install script)
  3. postinstall

Now, the problem is that required deps/artifacts needed to be extract before node-gyp rebuild can be run but the preinstall script that is supposed to extract the dependencies is skipped on Darwin.

So when installing on Darwin, node-gyp rebuild will fail with the following message

gyp info it worked if it ends with ok
│ gyp info using node-gyp@9.4.0
│ gyp info using node@18.12.1 | darwin | arm64
│ gyp info find Python using Python version 3.11.5 found at "/opt/homebrew/opt/python@3.11/bin/python3.11"
│ gyp info spawn /opt/homebrew/opt/python@3.11/bin/python3.11
│ gyp info spawn args [
...
│ gyp info spawn args ]
│ /bin/sh: deps/artifacts/bin/curl-config: No such file or directory
│ gyp: Call to 'deps/artifacts/bin/curl-config --static-libs' returned exit status 127 while in binding.gyp. while trying to load binding.gyp

I guess the node-gyp rebuild step is intended to be skipped on Darwin, but it wouldn't with the current setup.

If no rebuild is intended, the solution is to simply add an empty install script so the default behavior will not click in. e.g.

"scripts": {
  "install": "true"
}
andclt commented 9 months ago

Hi @alvis ,

Could you please specify which aws-lambda-ric and npm versions are you using?

On MacOS, with npm v9.5.1 and aws-lambda-ric v3.0.0 I am not able to face the issue you described:

npm install

> aws-lambda-ric@3.0.0 preinstall
> ./scripts/preinstall.sh

aws-lambda-cpp does not build on OS X. Skipping the preinstall step.

> aws-lambda-ric@3.0.0 postinstall
> ./scripts/postinstall.sh

aws-lambda-cpp does not build on OS X. Skipping the postinstall step.
Cleaning up source dependencies to save space

up to date, audited 462 packages in 895ms

65 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

Please note that it is not possible to fully install aws-lambda-ric on MacOS since aws-lambda-cpp does not build on OS X.

alvis commented 9 months ago

Hi @andclt I was trying to install aws-lambda-ric@3.0.0 with pnpm@8.7.0. I tested to install it with npm and it's fine as mentioned. Probably there is discrepancy on how these two managers manage the life cycle scripts.

It's fine aws-lambda-ric can't be fully installed on MacOS coz the code will be deployed on a linux container.

We're using pnpm for managing our monorepo so changing to npm is unlikely. Our current workaround is to install it with --ignore-scripts to get aws-lambda-ric installed for development on Mac. Certainly not ideal.

andclt commented 9 months ago

Got it thanks.

Probably there is discrepancy on how these two managers manage the life cycle scripts.

Yes, the difference is that npm is looking for either an install or preinstall script whilepnpm just checks for an install script.

andclt commented 9 months ago

I can confirm that with pnpm v8.9.2 this is fixed:

pnpm install aws-lambda-ric

Packages: +118
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Progress: resolved 118, reused 118, downloaded 0, added 118, done
node_modules/.pnpm/aws-lambda-ric@3.0.0/node_modules/aws-lambda-ric: Running preinstall script, done in 155ms
node_modules/.pnpm/aws-lambda-ric@3.0.0/node_modules/aws-lambda-ric: Running postinstall script, done in 158ms

dependencies:
+ aws-lambda-ric 3.0.0

Done in 3.3s