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 thepackage.json
file todist/index.js
. Themain
in theproject.yml
is for setting the name of the entrypoint function in case its name is different thanmain
.@mariocastrosquella
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 withdoctl
thatdocts
addresses such as:project.yml
package.json
sdocts
addresses these problems by:Auto-updating
project.yml
when you add or remove functions to/from your projectAllowing 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 respectivepackages/
directories … and moreFeel free to check it out on Github and on NPM