claudiajs / claudia

Deploy Node.js projects to AWS Lambda and API Gateway easily
https://claudiajs.com
MIT License
3.8k stars 274 forks source link

Error after deploy with claudia - module initialization error: TypeError #192

Closed pawel-pelak-wb closed 5 years ago

pawel-pelak-wb commented 5 years ago

HI

after deploy I got this error:

module initialization error: TypeError
at _addListener (events.js:239:11)
at Server.addListener (events.js:297:10)
at new Server (_http_server.js:269:10)
at Object.createServer (http.js:34:10)
at Object.createServer (/var/task/node_modules/aws-serverless-express/src/index.js:170:23)
at Object.<anonymous> (/var/task/lambda.js:13:37)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)

My local instance works well.

This is my server.js file.

const app = require("./backend/app");
const debug = require("debug")("node-angular");
const http = require("http");

const onError = error => {
  if (error.syscall !== "listen") {
    throw error;
  }
  const bind = typeof addr === "string" ? "pipe " + addr : "port " + port;
  switch (error.code) {
    case "EACCES":
      console.error(bind + " requires elevated privileges");
      process.exit(1);
      break;
    case "EADDRINUSE":
      console.error(bind + " is already in use");
      process.exit(1);
      break;
    default:
      throw error;
  }

const onListening = () => {
  const addr = server.address();
  const bind = typeof addr === "string" ? "pipe " + addr : "port " + port;
  debug("Listening on " + bind);
};
const port = "3000";
app.set("port", port);
const server = http.createServer(app);
server.on("error", onError);
//server.on("listening", onListening);
//server.listen(port);
module.exports = server;
gojko commented 5 years ago

I suggest running claudia pack and see what gets sent to AWS. It's possible that some dependencies are not included due to package config. Check if you can run it locally from the packaged source. Also, check if the Node.Js version you use for the runtime supports all the deps (so run locally in the same Node instance as remotely).

gojko commented 5 years ago

closing this due to inactivity