serverless / serverless/examples

cannot find module Error despite depedencies being installed

Open
#574 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
11.5k
Forks
4.4k
Avg merge
2h 55m
Merged PRs (30d)
3

Description

Hey folks,

Following the serverless docs for the aws-node-twilio example, I get the following message even though I installed all dependencies (tried via npm and yarn as well). I removed the node_modules directory and ran a full npm install as well and that doesn't change anything.

Weird thing is that a local invoke will work but not a 'normal' invoke eve though I did a sls deploy to make sure all the deps are deployed.

I tried with the latest twilio package but I also get an error.

Any thoughts ?

{
    "errorType": "Runtime.ImportModuleError",
    "errorMessage": "Error: Cannot find module 'underscore'\nRequire stack:\n- /var/task/node_modules/twilio/lib/webhooks.js\n- /var/task/node_modules/twilio/lib/index.js\n- /var/task/handler.js\n- /var/runtime/UserFunction.js\n- /var/runtime/index.js",
    "trace": [
        "Runtime.ImportModuleError: Error: Cannot find module 'underscore'",
        "Require stack:",
        "- /var/task/node_modules/twilio/lib/webhooks.js",
        "- /var/task/node_modules/twilio/lib/index.js",
        "- /var/task/handler.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:1015:30)",
        "    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1035:10)",
        "    at Module.load (internal/modules/cjs/loader.js:879:32)",
        "    at Function.Module._load (internal/modules/cjs/loader.js:724:14)",
        "    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)",
        "    at internal/main/run_main_module.js:17:47"
    ]
}
 
  Error --------------------------------------------------
 
  Error: Invoked function failed
      at AwsInvoke.log (/snapshot/serverless/lib/plugins/aws/invoke/index.js:100:31)
  From previous event:
      at Object.invoke:invoke [as hook] (/snapshot/serverless/lib/plugins/aws/invoke/index.js:23:12)
      at /snapshot/serverless/lib/classes/PluginManager.js:521:55
  From previous event:
      at PluginManager.invoke (/snapshot/serverless/lib/classes/PluginManager.js:521:22)
      at /snapshot/serverless/lib/classes/PluginManager.js:556:24
  From previous event:
      at PluginManager.run (/snapshot/serverless/lib/classes/PluginManager.js:556:8)
      at /snapshot/serverless/lib/Serverless.js:203:33
      at processImmediate (internal/timers.js:456:21)
      at process.topLevelDomainCallback (domain.js:137:15)
  From previous event:
      at Serverless.run (/snapshot/serverless/lib/Serverless.js:190:74)
      at /snapshot/serverless/scripts/serverless.js:50:26
 
  Get Support --------------------------------------------
     Docs:          docs.serverless.com
     Bugs:          github.com/serverless/serverless/issues
     Issues:        forum.serverless.com
 
  Your Environment Information ---------------------------
     Operating System:          linux
     Node Version:              12.18.1
     Framework Version:         2.15.0 (standalone)
     Plugin Version:            4.2.0
     SDK Version:               2.3.2
     Components Version:        3.4.3

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the aws-node-twilio example and its handler.js entry point, then compare the dependencies available during local invoke with those in the deployed function. Reproduce with sls deploy followed by a normal invoke and trace why twilio/lib/webhooks.js cannot load underscore. Done means the deployed example invokes successfully with underscore available.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, javascript, node.js
Domain
backend, cloud
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.