Hello, I’ve built a simple lambda function using netlify.
Git Repository: GitHub - edgar1506/netlify_question: POC NEtlify Fastify
Live site: https://competent-shockley-e44c09.netlify.app/api/
When I deploy locally using netlify dev, everything works fine:
GET requests work fine:
Request:
GET https://competent-shockley-e44c09.netlify.app/api/ HTTP/1.1
Response:
HTTP/1.1 200 OK
...
{
"data": "dummy GET"
}
Request:
POST https://competent-shockley-e44c09.netlify.app/api/ HTTP/1.1
Response:
HTTP/1.1 200 OK
...
{
"data": "dummy POST"
}
Request
POST https://competent-shockley-e44c09.netlify.app/api/ HTTP/1.1
Content-Type: application/json
{
"myKey": "myValue"
}
Response:
HTTP/1.1 200 OK
...
{
"data": "dummy POST"
}
However, when I run the deployed version, I start getting an error with POST requests than include a content body (all other requests listed above except the onw with content body work fine online too):
Request
POST https://competent-shockley-e44c09.netlify.app/api/ HTTP/1.1
Content-Type: application/json
{
"myKey": "myValue"
}
Response:
HTTP/1.1 502 Bad Gateway
{
"errorType": "Error",
"errorMessage": "Cannot find module 'string_decoder/'\nRequire stack:\n- /var/task/src/function.js\n- /var/task/function.js\n- /var/runtime/UserFunction.js\n- /var/runtime/index.js",
"trace": [
"Error: Cannot find module 'string_decoder/'",
"Require stack:",
"- /var/task/src/function.js",
"- /var/task/function.js",
"- /var/runtime/UserFunction.js",
"- /var/runtime/index.js",
" at Function.Module._resolveFilename (internal/modules/cjs/loader.js:815:15)",
" at Function.Module._load (internal/modules/cjs/loader.js:667:27)",
" at Module.require (internal/modules/cjs/loader.js:887:19)",
" at require (internal/modules/cjs/helpers.js:74:18)",
" at Request.Readable.setEncoding (/var/task/src/function.js:3949:25)",
" at rawBody (/var/task/src/function.js:21964:17)",
" at ContentTypeParser.run (/var/task/src/function.js:21931:9)",
" at handleRequest (/var/task/src/function.js:14883:43)",
" at runPreParsing (/var/task/src/function.js:25052:9)",
" at Object.routeHandler [as handler] (/var/task/src/function.js:25020:11)"
]
}
As far as I understand, string_decoder is a core Node module, and it works fine on my computer, but it doesn’t seem to find it in Netlify’s Node installation?


