Home
Support Forums

Netlify Functions AWS-SDK Local (netlify functions:serve)

Hello,

I am trying to locally test my netlify function which is using many different libraries including aws-sdk.
For some reason, I get the following error when trying to test my aws-sdk functions locally using either netlify functions:serve or netlify dev:

Error: Cannot find module ‘aws-sdk’

This error, however, does not occur when it has been deployed to netlify. Only locally it is running into this problem. The example can be found at:
curess-develop.netlify.app

All other libraries seem to run fine. The library is installed using a package.json inside my functions folder. Currently tested by installing it in both devDependency and normal dependency.

Many thanks in advance :slight_smile:

FULL ERROR LOG:

Error: Cannot find module ‘aws-sdk’
Require stack:

  • C:\Users\joey\Documents\Projects\Boilers\mui5.netlify\functions-serve\upload-file\src\functions\upload-file.js
  • C:\Users\joey\Documents\Projects\Boilers\mui5.netlify\functions-serve\upload-file\upload-file.js
  • C:\Users\joey\AppData\Roaming\nvm\v16.3.0\node_modules\netlify-cli\node_modules\lambda-local\build\lambdalocal.js
  • C:\Users\joey\AppData\Roaming\nvm\v16.3.0\node_modules\netlify-cli\src\lib\functions\runtimes\js\index.js
  • C:\Users\joey\AppData\Roaming\nvm\v16.3.0\node_modules\netlify-cli\src\lib\functions\runtimes\index.js
  • C:\Users\joey\AppData\Roaming\nvm\v16.3.0\node_modules\netlify-cli\src\lib\functions\registry.js
  • C:\Users\joey\AppData\Roaming\nvm\v16.3.0\node_modules\netlify-cli\src\lib\functions\server.js
  • C:\Users\joey\AppData\Roaming\nvm\v16.3.0\node_modules\netlify-cli\src\commands\functions\serve.js
  • C:\Users\joey\AppData\Roaming\nvm\v16.3.0\node_modules\netlify-cli\node_modules@oclif\config\lib\plugin.js
  • C:\Users\joey\AppData\Roaming\nvm\v16.3.0\node_modules\netlify-cli\node_modules@oclif\config\lib\config.js
  • C:\Users\joey\AppData\Roaming\nvm\v16.3.0\node_modules\netlify-cli\node_modules@oclif\config\lib\index.js
  • C:\Users\joey\AppData\Roaming\nvm\v16.3.0\node_modules\netlify-cli\node_modules@oclif\command\lib\command.js
  • C:\Users\joey\AppData\Roaming\nvm\v16.3.0\node_modules\netlify-cli\node_modules@oclif\command\lib\index.js
  • C:\Users\joey\AppData\Roaming\nvm\v16.3.0\node_modules\netlify-cli\src\index.js
  • C:\Users\joey\AppData\Roaming\nvm\v16.3.0\node_modules\netlify-cli\bin\run
    uire stack:
    :\Users\joey\Documents\Projects\Boilers\mui5.netlify\functions-serve\upload-file\src\functions\upload-file.js
    :\Users\joey\Documents\Projects\Boilers\mui5.netlify\functions-serve\upload-file\upload-file.js
    :\Users\joey\AppData\Roaming\nvm\v16.3.0\node_modules\netlify-cli\node_modules\lambda-local\build\lambdalocal.js
    :\Users\joey\AppData\Roaming\nvm\v16.3.0\node_modules\netlify-cli\src\lib\functions\runtimes\js\index.js
    :\Users\joey\AppData\Roaming\nvm\v16.3.0\node_modules\netlify-cli\src\lib\functions\runtimes\index.js
    :\Users\joey\AppData\Roaming\nvm\v16.3.0\node_modules\netlify-cli\src\lib\functions\registry.js
    :\Users\joey\AppData\Roaming\nvm\v16.3.0\node_modules\netlify-cli\src\lib\functions\server.js
    :\Users\joey\AppData\Roaming\nvm\v16.3.0\node_modules\netlify-cli\src\commands\functions\serve.js
    :\Users\joey\AppData\Roaming\nvm\v16.3.0\node_modules\netlify-cli\node_modules@oclif\config\lib\plugin.js
    :\Users\joey\AppData\Roaming\nvm\v16.3.0\node_modules\netlify-cli\node_modules@oclif\config\lib\config.js
    :\Users\joey\AppData\Roaming\nvm\v16.3.0\node_modules\netlify-cli\node_modules@oclif\config\lib\index.js
    :\Users\joey\AppData\Roaming\nvm\v16.3.0\node_modules\netlify-cli\node_modules@oclif\command\lib\command.js
    :\Users\joey\AppData\Roaming\nvm\v16.3.0\node_modules\netlify-cli\node_modules@oclif\command\lib\index.js
    :\Users\joey\AppData\Roaming\nvm\v16.3.0\node_modules\netlify-cli\src\index.js
    :\Users\joey\AppData\Roaming\nvm\v16.3.0\node_modules\netlify-cli\bin\run
    Function.Module._resolveFilename (node:internal/modules/cjs/loader:941:15)
    Function.Module._load (node:internal/modules/cjs/loader:774:27)
    Module.require (node:internal/modules/cjs/loader:1013:19)
    require (node:internal/modules/cjs/helpers:93:18)
    Object. (C:\Users\joey\Documents\Projects\Boilers\mui5\functions\lib\s3-util.ts:2:17)
    Module._compile (node:internal/modules/cjs/loader:1109:14)
    Object.Module._extensions…js (node:internal/modules/cjs/loader:1138:10)
    Module.load (node:internal/modules/cjs/loader:989:32)
    Function.Module._load (node:internal/modules/cjs/loader:829:14)
    Module.require (node:internal/modules/cjs/loader:1013:19)

Hi @Joey_Teunissen,

This doesn’t normally happen. Is there a repo we can test?

Hello @hrishikesh,

I have removed all secret data and pushed a repo to Joey Teunissen / Help Netlify · GitLab.
Please let me know if you can find the problem

Note that only the following functions / lib use the S3 plugin:

functions/upload-file.ts
functions/download-file.ts
functions/lib/s3-util.ts

Hi @Joey_Teunissen,

Thanks for all the files. I moved all of your dependencies in just one package.json as the root of the repo. I am not getting the error you mentioned, however I’m facing this problem:

I’m currently waiting for the team to comment on that, but till then if you can try moving all dependencies to the main package.json, it would be great.