Based on this environment setup code
My guess is to focus on how this applies in your particular case apps/your_custom_app/package.json
These two apps/frappe/package.json and apps/erpnext/package.son will give you clues too.
Perhaps this tutorial example will help https://classic.yarnpkg.com/en/docs/creating-a-package/
edit: This could be a clue or tip How to import a .js module in Frappe?
and also this How to add a node module to a custom app?