Question

How to use private repo and local lib in typescript serverless functions?

I am struggling to find documentation or an answer through self testing to get my infrastructure setup.

I have simple hello world packages setup deploying to app platform through the github repo integration from control panel, but now I want to add private npm repo and a local root lib folder. Neither of which I am having much success with.

  1. How can I use the environment variables for my .npmrc? It recognizes my npm repo as github but it keeps telling me I have no token.
@scope:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken:${NPM_TOKEN}

I have tried echoing from preinstall, prepare, I have tried export NPM_TOKEN=NPM_TOKEN

  1. How can I reference the root lib/ folder for my functions using typescript? My function just fails when I try to call it, it doesn’t give me any error during build.

Some examples covering these use cases would be extremely helpful.


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.

After ALOT of trial and error (159 commits, since I was using app platform integration for deployments).

I found a solution to root lib, however it doesn’t feel quite correct. But I’ll post it here so others may work with it.

By installing root lib via package.json, but I have to directly reference the dist folder instead of just the base package, even though the lib package.json has main as dist/index.js

//packages/my-package/function1/package.json
    "@myscope/api-lib": "file:../../../lib/dist",

I am still looking for answers to how to install a private npm repo, and I would like possible alternatives to this solution as it feels a bit wrong.

**Note: It seems the Functions’s do not like having the tsconfig setup as NodeNext / Modules, I ended up with a lot of problems with that before reverting the output back to commonjs **

Try DigitalOcean for free

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

Sign up

Featured on Community

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

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

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

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