aws / aws-lambda-base-images

Apache License 2.0
669 stars 110 forks source link

Error `Unable to load legacy provider.` from Node.js 18 #114

Open kennyhyun opened 1 year ago

kennyhyun commented 1 year ago
$ docker run -e "NODE_OPTIONS=--openssl-legacy-provider" --entrypoint="" public.ecr.aws/lambda/nodejs:18  node -e "require('crypto').Hash('md4')"

gives following error

Unable to load legacy provider.
node:internal/crypto/hash:69
  this[kHandle] = new _Hash(algorithm, xofLen);
                  ^

Error: error:12800067:DSO support routines::could not load the shared library
    at new Hash (node:internal/crypto/hash:69:19)
    at Object.Hash (node:internal/crypto/hash:62:12)
    at [eval]:1:19
    at Script.runInThisContext (node:vm:123:12)
    at Object.runInThisContext (node:vm:299:38)
    at node:internal/process/execution:79:19
    at [eval]-wrapper:6:22
    at evalScript (node:internal/process/execution:78:60)
    at node:internal/main/eval_string:28:3 {
  opensslErrorStack: [
    'error:03000086:digital envelope routines::initialization error',
    'error:0308010C:digital envelope routines::unsupported',
    'error:07880025:common libcrypto routines::reason(524325)',
    'error:12800067:DSO support routines::could not load the shared library'
  ],
  library: 'DSO support routines',
  reason: 'could not load the shared library',
  code: 'ERR_OSSL_DSO_COULD_NOT_LOAD_THE_SHARED_LIBRARY'
}

Node.js v18.17.1

Actually, I have the same error using webpack

It's Node.js problem but this would be quite essential in node.js@18 and hard to understand what is the reason.


found this discussion https://github.com/openssl/openssl/discussions/21417

and /var/lang/lib/ossl-modules/legacy.so was found in this image

but

bash-4.2# LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/var/lang/lib:/var/lang/lib/ossl-modules NODE_OPTIONS=--openssl-legacy-provider node -e "require('crypto').Hash('md4')"
Unable to load legacy provider.

still has problem


Found workaround. OPENSSL_MODULES=/var/lang/lib/ossl-modules

$ docker run --entrypoint="" -it public.ecr.aws/lambda/nodejs:18 bash
bash-4.2# OPENSSL_MODULES=/var/lang/lib/ossl-modules NODE_OPTIONS=--openssl-legacy-provider node -e "require('crypto').Hash('md4')"
bash-4.2#

inspired by https://github.com/openssl/openssl/issues/13115#issuecomment-707481332

kennyhyun commented 1 year ago

to who has this issue with webpack,

maybe worth to follow this https://stackoverflow.com/a/73465262/4902709

mahesh-opensolar commented 2 months ago

Thanks @kennyhyun This saved my time. thanks a lot