2

Setup

I have a monorepo setup with the following file structure:

├── functions
│   ├── src
│   └── package.json
├── shared
|   ├── dist
|   ├── src
|   └── package.json
├── frontend
|    └── ...
└── firebase.json

Approach 1 (failed)

./shared is holding TypeScript classes shared among the ./backend and ./frontend. Ideally, I want to reference the shared lib from the functions/package.json using a symlink to avoid that I have to re-install after every change to my shared code (where most of the functionality resides).

However, this does not work (neither using link:, nor an absolute file: path, nor an relative file: path)

// functions/package.json
  ...
  "dependencies": {
    "shared": "file:/home/boern/Desktop/wd/monorepo/shared"
    ...
  }

resulting into an error upon firebase deploy --only functions (error Package "shared" refers to a non-existing file '"home/boern/Desktop/wd/monorepo/shared"'). The library (despite being present in ./functions/node_modules/) was not transferred to the server?

Approach 2 (failed)

Also, setting "functions": {"ignore": []} in firebase.json did not help.

Approach 4 (works, but lacks requirement a) see Goal)

The only thing that DID work, was a proposal by adevine on Github:

// functions/package.json
  ...
  "scripts": {
     ...
    "preinstall": "if [ -d ../shared ]; then npm pack ../shared; fi"
  },
  "dependencies": {
    "shared": "file:./bbshared-1.0.0.tgz"
    ...
  }

Goal

Can someone point out a way to reference a local library in a way that a) ./functions always uses an up-to-date version during development and b) deployment using the stock Firebase CLI succeeds (and not, e.g. using firelink)? Or is this simply not supported yet?

Boern
  • 6,447
  • 4
  • 49
  • 81
  • Tried [this answer out](https://stackoverflow.com/a/58877253/3068190) yet? – samthecodingman Feb 17 '21 at 13:10
  • Please edit that into the question, comments are ephemeral. – jonrsharpe Feb 17 '21 at 13:57
  • 1
    Mono repo are no supported yet, you can use another approachs to deploy a mono repo using for example google cloub build or deploy your functions using google cloud to deploy each function separately. – vi calderon Mar 03 '21 at 19:29
  • Hey mate, did you find any solution ? – Titou Sep 14 '21 at 23:13
  • Hey @Titou, unfortunately not. I went up zipping my shared library and copying it to the functions folder. Involves manual effort (i.e. increasing the version) every time. – Boern Sep 15 '21 at 06:55
  • I'm turning crazy with this problem ! Even when I "npm pack" my local dependency, I change my package.json to link to ./core.1.0.0.tgz for example, install using npm i, build using tsc and then deploy using firebase deploy --only functions, it's not working... Error: Error parsing triggers: Cannot find module 'core/src/services/event' – Titou Sep 21 '21 at 14:09
  • I'll post my crappy solution next week ! – Boern Sep 22 '21 at 08:36

1 Answers1

1

Here's my workaround to make approach 4 work:

rm -rf ./node_modules
yarn cache clean # THIS IS IMPORTANT
yarn install

Run this from the ./functions folder

Boern
  • 6,447
  • 4
  • 49
  • 81