Hello everyone, a bit of clarification on my last ...
# help
m
Hello everyone, a bit of clarification on my last question. I have some API endpoints in which lambdas I have imported these two packages:
Copy code
import { fileTypeFromBuffer } from 'file-type';
import AWS from 'aws-sdk';
When I try sending a request to any of those endpoints, I get this error message from lambda CloudWatch log:
Copy code
2022-05-16T14:45:28.071Z	undefined	ERROR	Uncaught Exception 	
{
    "errorType": "Runtime.ImportModuleError",
    "errorMessage": "Error: Cannot find module 'node:fs'\nRequire stack:\n- /var/task/src/endpoints/files/create.js\n- /var/runtime/UserFunction.js\n- /var/runtime/index.js",
    "stack": [
        "Runtime.ImportModuleError: Error: Cannot find module 'node:fs'",
        "Require stack:",
        "- /var/task/src/endpoints/files/create.js",
        "- /var/runtime/UserFunction.js",
        "- /var/runtime/index.js",
        "    at _loadUserApp (/var/runtime/UserFunction.js:100:13)",
        "    at Object.module.exports.load (/var/runtime/UserFunction.js:140:17)",
        "    at Object.<anonymous> (/var/runtime/index.js:43:30)",
        "    at Module._compile (internal/modules/cjs/loader.js:999:30)",
        "    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)",
        "    at Module.load (internal/modules/cjs/loader.js:863:32)",
        "    at Function.Module._load (internal/modules/cjs/loader.js:708:14)",
        "    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)",
        "    at internal/main/run_main_module.js:17:47"
    ]
}
I suspect that Node's filesystem is not importing these packages correctly. Any suggestion on what might be the problem and/or how to fix it?
Also to clarify, the problem occurs only on the deployed version of the app. The local version of the app (from
npx sst start
) works correctly.
t
can you try using node16 as the runtime?
there's a new syntax for imports that I'm not sure if node14 is supported
m
But can you take a look at this: https://seed.run/docs/adding-nodejs-projects? @thdxr
@thdxr will try out your solution, will return with the result asap.
@thdxr I am getting this now since implementing the code into my index.js:
Copy code
Error: The specified runtime is not supported for sst.Function. Only NodeJS, Python, Go, and .NET runtimes are currently supported.
t
need to update to latest sst
just to double check though do you have any imports from
node:fs
in
files/create.js
?
m
Nope, I don't have any imports from node:fs in files/create.js
And I can't update to the latest SST rn
t
It seems like this
file-type
library is using the new node imports so doing
Copy code
import fs from "node:fs"
instead of
Copy code
import fs from "fs"
and I don't think node14 supports this (can't verify though)
v14.18.0 and above support it, I'd make sure your runtime is set to node14 and if it still doesn't work it means aws lambda doesn't support it
t
@thdxr I had posted a similar question about 10 minutes prior. Do you think it could also be a Node version issue?
t
I'm not sure about your issue trey
m
@thdxr will try it out now, will report the results
@thdxr IT WORKS!!!! The fix was adding this to Stacks/index.js:
Copy code
app.setDefaultFunctionProps({
    runtime: "nodejs14.x",
  });
Thank you so much mate @thdxr
t
Cool!