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: {}
packages:
- name: sample
environment: { }
parameters: { }
annotations: { }
functions:
- 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'"
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!
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:
project.ymlpackage.jsonsdocts addresses these problems by:
Auto-updating project.yml when you add or remove functions to/from your project
Allowing you to install all dependencies at one place (in the project’s package.json)
Providing a build command which builds all your functions to their respective packages/ directories
… and more
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Scale up as you grow — whether you're running one virtual machine or ten thousand.

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.
