Question

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: {}
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'"

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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.