Unable to use Dependencies in a DigitalOcean FaaS

93 Views Asked by At

I've created a simple FaaS in DigitalOcean but it fails on the very first line. I'm using the web interface to remove as many variables as possible.

NodeMailer = require('nodemailer');

// ReferenceError: require is not defined in ES module scope, you can use import instead

So I try this with the following result:

import NodeMailer from 'nodemailer';

// Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'nodemailer' imported from /tmp/index.mjs

What am I missing?

1

There are 1 best solutions below

0
Donnie On BEST ANSWER

Creating a function that has multiple files or contains dependencies must be done using the CLI. The web interface is not capable since npm (or equivalent package manager) is required.

To start locally, install the Serverless package, then:

  • doctl serverless init <path/to/directory>
  • doctl serverless watch <path/to/directory> (Optional while developing)
  • Or
  • doctl serverless deploy <path/to/directory>