question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to load module due to `finalhandler` dependency

See original GitHub issue

This is a Bug Report

Description

  • What went wrong? Express-based web app won’t run on AWS, but it works locally using the serverless-offline plugin.

  • What did you expect should have happened? Expected to run with no errors on AWS Lambda environment.

  • What was the config you used?

Here’s the serverless.yml:

service: testing-app

plugins:
  - serverless-offline

provider:
  name: aws
  runtime: nodejs6.10
  stage: dev
  region: us-west-2

functions:
  app:
    handler: server.handler
    events:
      - http: ANY /
      - http: 'ANY {proxy+}'

Here’s package.json:

{
  "name": "testing",
  "version": "1.0.0",
  "private": true,
  "main": "server.js",
  "dependencies": {
    "async": "^2.6.0",
    "bcrypt-nodejs": "0.0.3",
    "body-parser": "^1.13.1",
    "capitalize": "^1.0.0",
    "connect-flash": "^0.1.1",
    "cookie-parser": "^1.3.5",
    "dateformat": "^3.0.2",
    "ejs": "^2.3.2",
    "express": "^4.16.2",
    "express-csv": "^0.6.0",
    "express-session": "^1.11.3",
    "format-currency": "^1.0.0",
    "formidable": "^1.1.1",
    "moment": "^2.19.2",
    "morgan": "^1.6.0",
    "mysql": "^2.7.0",
    "nodemailer": "^4.4.0",
    "passport": "^0.2.2",
    "passport-local": "^1.0.0",
    "phantom-html-to-pdf": "^0.5.5",
    "serverless-http": "^1.5.2",
    "slugify": "^1.2.4"
  },
  "devDependencies": {
    "serverless-offline": "^3.16.0"
  }
}
  • What stacktrace or error message from your provider did you see?

Here’s the Lambda function logs:

START RequestId: 03466ae4-d11e-11e7-9f97-2f79ff0bb01d Version: $LATEST
Unable to import module 'server': Error
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/var/task/node_modules/finalhandler/index.js:14:29)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
END RequestId: 03466ae4-d11e-11e7-9f97-2f79ff0bb01d
REPORT RequestId: 03466ae4-d11e-11e7-9f97-2f79ff0bb01d	Duration: 6.27 ms	Billed Duration: 100 ms Memory Size: 1024 MB	Max Memory Used: 22 MB	

For feature proposals:

Similar or dependent issues:

Additional Data

The issues seems to be related to the fact that it can’t load finalhandler. I checked the package generated by serverless and the module is present under node_modules.

Found this: https://github.com/pillarjs/finalhandler/issues/19 , but it doesn’t help.

  • Serverless Framework Version you’re using:
serverless -v
1.18.0
  • Operating System: MacOS 10.12.6

  • Stack Trace:

  • Provider Error messages:

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
seedencommented, Oct 26, 2018

I have same error with latest serverless.

0reactions
dschepcommented, Jan 7, 2019

I’m not sure why sls offline is working… but you say you’re using express but I don’t see serverless-http in your plugins, so I wouldn’t expect it to work.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I resolve "Cannot find module" error using Node.js?
Probably a good first troubleshooting step whenever a weird dependency issue pops up that npm install / npm update won't solve. This solved...
Read more >
finalhandler - npm
Start using finalhandler in your project by running `npm i finalhandler`. There are 1122 other projects in the npm registry using finalhandler.
Read more >
Modules Part 1 - Loading modules with require() - byte archer
NAVIGATION Modules organize program code Load your own source files using relative path Supported types: .js, .json and .node Core modules bundled in...
Read more >
How to Lock a Nested NPM Dependency to Some Exact Version
Usually, it is not a problem thanks to NPM tree resolution. ... nearly impossible to find a working combination of both modules that...
Read more >
Unable to install dependencies, NPM install not working
23 error Failed at the magicmirror@2.0.0 start script 'electron js/electron.js'. 23 error Make sure you have the latest version of node.js and ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found