How to define entry point of a function that's under a /dist directory?

I’m developing functions using the NodeJS runtime using TypeScript, and my compiled JavaScript code goes to a /dist directory, with the main function residing in index.js. I tried the following configuration in project.yml:

environment: {}
parameters: {}
  - name: sample
    environment: { }
    parameters: { }
    annotations: { }
      - name: hello
        binary: false
        main: 'dist/index.js'
        runtime: 'nodejs:default'
        web: true
        parameters: { }
        environment: { }
        annotations: { }
        limits: { }

It deploys without any apparent issue, but when I try to run the function, it cannot start, and I get the following error in the logs:

"2022-07-24T17:15:51.915241077Z stdout: Action entrypoint 'dist/index.js' is not a function."

If I change the main property to /dist I get something like this:

"2022-07-24T17:21:27.668525053Z stdout: Error: Cannot find module '/tmp/fP5MxYsZ'"

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

I managed to solve this myself. It turns out that I had not set the main property in the package.json file to dist/index.js. The main in the project.yml is for setting the name of the entrypoint function in case its name is different than main.


Props to resolving the issue. Typescript on doctl is quite lacking. Aside creating the initial project, there’s nothing more it does unless you are ready to deploy.

I’ve been working on a CLI library which improves the development experience when working with Typescript serverless projects.

It’s called docts. There are some pain points with doctl that docts addresses such as:

  • No autoupdate of project.yml
  • Managing different versions of libraries across several function package.jsons

docts addresses these problems by:

  1. Auto-updating project.yml when you add or remove functions to/from your project

  2. Allowing you to install all dependencies at one place (in the project’s package.json)

  3. Providing a build command which builds all your functions to their respective packages/ directories … and more

Feel free to check it out on Github and on NPM

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

card icon
Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Sign up
card icon
Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We’d like to help.

Learn more
card icon
Become a contributor

You get paid; we donate to tech nonprofits.

Learn more
Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow – whether you’re running one virtual machine or ten thousand.

Learn more ->
DigitalOcean Cloud Control Panel
Get started for free

Enter your email to get $200 in credit for your first 60 days with DigitalOcean.

New accounts only. By submitting your email you agree to our Privacy Policy.