We're trying to run a lambda locally via `sst star...
# sst
r
We're trying to run a lambda locally via
sst start
which references the sharp library. It's on a Windows platform, we've tried specifying the sharp dependency in
bundle.nodeModules
(and in
bundle.externalModules
) but we're getting the error when the function runs:
Copy code
Uncaught Exception      {"errorType":"Error","errorMessage":"\nSomething went wrong installing the \"sharp\" module\n\nCannot find module '../build/Release/sharp-win32-x64.node'\nRequire stack:\n- C:\\dev\\omw-pso-be\\.sst\\artifacts\\f79e38b8\\src\\main\\handler\\omw\\getOmwResponse.js\n- C:\\dev\\omw-pso-be\\node_modules\\@serverless-stack\\aws-lambda-ric\\lib\\utils\\UserFunction.js\n- C:\\dev\\omw-pso-be\\node_modules\\@serverless-stack\\aws-lambda-ric\\lib\\index.js\n- C:\\dev\\omw-pso-be\\node_modules\\@serverless-stack\\aws-lambda-ric\\bin\\index.js\n\nPossible solutions:\n- Install with the --verbose flag and look for errors: \"npm install --ignore-scripts=false --verbose sharp\"\n- Install for the current runtime: \"npm install --platform=win32 --arch=x64 sharp\"\n- Consult the installation documentation: <https://sharp.pixelplumbing.com/install>","stack":["Error: ","Something went wrong installing the \"sharp\" module","","Cannot find module '../build/Release/sharp-win32-x64.node'","Require 
stack:","- C:\\dev\\omw-pso-be\\.sst\\artifacts\\f79e38b8\\src\\main\\handler\\omw\\getOmwResponse.js","- C:\\dev\\omw-pso-be\\node_modules\\@serverless-stack\\aws-lambda-ric\\lib\\utils\\UserFunction.js","- C:\\dev\\omw-pso-be\\node_modules\\@serverless-stack\\aws-lambda-ric\\lib\\index.js","- C:\\dev\\omw-pso-be\\node_modules\\@serverless-stack\\aws-lambda-ric\\bin\\index.js","","Possible solutions:","- Install with the --verbose flag and look for errors: \"npm install --ignore-scripts=false --verbose sharp\"","- Install for the current runtime: \"npm install --platform=win32 --arch=x64 sharp\"","- Consult the installation documentation: <https://sharp.pixelplumbing.com/install>","    at node_modules/sharp/lib/sharp.js (C:\\dev\\omw-pso-be\\.sst\\artifacts\\f79e38b8\\src\\main\\handler\\omw\\getOmwResponse.js:39896:13)","    at __require (C:\\dev\\omw-pso-be\\.sst\\artifacts\\f79e38b8\\src\\main\\handler\\omw\\getOmwResponse.js:38:44)","    at node_modules/sharp/lib/constructor.js (C:\\dev\\omw-pso-be\\.sst\\artifacts\\f79e38b8\\src\\main\\handler\\omw\\getOmwResponse.js:39909:5)","    at __require (C:\\dev\\omw-pso-be\\.sst\\artifacts\\f79e38b8\\src\\main\\handler\\omw\\getOmwResponse.js:38:44)","    at node_modules/sharp/lib/index.js (C:\\dev\\omw-pso-be\\.sst\\artifacts\\f79e38b8\\src\\main\\handler\\omw\\getOmwResponse.js:43471:17)","    at __require (C:\\dev\\omw-pso-be\\.sst\\artifacts\\f79e38b8\\src\\main\\handler\\omw\\getOmwResponse.js:38:44)","    at Object.<anonymous> (C:\\dev\\omw-pso-be\\.sst\\artifacts\\f79e38b8\\src\\main\\handler\\omw\\getOmwResponse.js:75153:31)","    at Module._compile (internal/modules/cjs/loader.js:1085:14)","    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)","    at Module.load (internal/modules/cjs/loader.js:950:32)"]}
How should we go about specifying this for
sst start
?
We're actually seeing this on the deployment via
sst deploy
too, using version 0.56.2
Same error but different OS target for the sharp dependency
Copy code
2022-01-05T15:57:40.340Z	undefined	ERROR	Uncaught Exception 	{
    "errorType": "Error",
    "errorMessage": "\nSomething went wrong installing the \"sharp\" module\n\nCannot find module '../build/Release/sharp-linux-x64.node'\nRequire stack:\n- /var/task/node_modules/sharp/lib/sharp.js\n- /var/task/node_modules/sharp/lib/constructor.js\n- /var/task/node_modules/sharp/lib/index.js\n- /var/task/src/main/handler/omw/getOmwResponse.js\n- /opt/nodejs/node_modules/@thundra/core/dist/thundra.js\n- /opt/nodejs/node_modules/@thundra/core/dist/thundraBridge.js\n- /opt/nodejs/node_modules/@thundra/core/dist/bootstrap/lambda/index.js\n- internal/preload\n\nPossible solutions:\n- Install with the --verbose flag and look for errors: \"npm install --ignore-scripts=false --verbose sharp\"\n- Install for the current runtime: \"npm install --platform=linux --arch=x64 sharp\"\n- Consult the installation documentation: <https://sharp.pixelplumbing.com/install>",
    "stack": [
        "Error: ",
        "Something went wrong installing the \"sharp\" module",
        "",
        "Cannot find module '../build/Release/sharp-linux-x64.node'",
        "Require stack:",
        "- /var/task/node_modules/sharp/lib/sharp.js",
        "- /var/task/node_modules/sharp/lib/constructor.js",
        "- /var/task/node_modules/sharp/lib/index.js",
        "- /var/task/src/main/handler/omw/getOmwResponse.js",
        "- /opt/nodejs/node_modules/@thundra/core/dist/thundra.js",
        "- /opt/nodejs/node_modules/@thundra/core/dist/thundraBridge.js",
        "- /opt/nodejs/node_modules/@thundra/core/dist/bootstrap/lambda/index.js",
        "- internal/preload",
        "",
        "Possible solutions:",
        "- Install with the --verbose flag and look for errors: \"npm install --ignore-scripts=false --verbose sharp\"",
        "- Install for the current runtime: \"npm install --platform=linux --arch=x64 sharp\"",
        "- Consult the installation documentation: <https://sharp.pixelplumbing.com/install>",
        "    at Object.<anonymous> (/var/task/node_modules/sharp/lib/sharp.js:30:9)",
        "    at Module._compile (internal/modules/cjs/loader.js:1085:14)",
        "    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)",
        "    at Module.load (internal/modules/cjs/loader.js:950:32)",
        "    at Function.Module._load (internal/modules/cjs/loader.js:790:12)",
        "    at Module.require (internal/modules/cjs/loader.js:974:19)",
        "    at Module.Hook._require.Module.require (/opt/nodejs/node_modules/require-in-the-middle/index.js:60:37)",
        "    at Module.Hook._require.Module.require (/opt/nodejs/node_modules/require-in-the-middle/index.js:60:37)",
        "    at Module.Hook._require.Module.require (/opt/nodejs/node_modules/require-in-the-middle/index.js:60:37)",
        "    at Module.Hook._require.Module.require (/opt/nodejs/node_modules/require-in-the-middle/index.js:60:37)"
    ]
}
I was thinking about why we hadn't seen this before and I think it's because we typically deploy from Seed which is running linux instances for the build. Whereas here we're doing a deploy from a local machine which has MacOS or Windows. Therefore, I the question is, is there a way to instruct the build process to run
npm install --platform=linux --arch=x64 sharp
for a package defined in nodeModules ?
t
Can those cli flags be set through env variables?
r
Possibly, I'll investigate
Doesn't seem so, I might just use a layer
t
This doesn't work for sst start either?