title: Sharing code between Firebase Functions and React
body: <p>I'm using Firebase functions with a React application. I have some non-trivial code that I don't want to duplicate, so I want to share it between the deployed functions and my React client. I've got this working locally in my React client (though I haven't tried deploying) - but I can't deploy my functions.</p>
  
  <p>The first thing I tried was npm link. This worked locally, but the functions won't deploy (which makes sense, since this leaves no dependency in your package.json). Then I tried npm install ../shared/ - this looked promising because it did leave a dependency in package.json with a file: prefix - but Firebase still won't deploy with this (error below).</p>
  
  <p>My project directory structure looks like this:</p>
  
  <pre><code>/ProjectDir
    firebase.json
    package.json (for the react app)
    /src
      * (react source files)
    /functions
      package.json (for firebase functions)
      index.js
    /shared
      package.json (for the shared module)
      index.js
  </code></pre>
  
  <p>My shared module package.json (extraneous details omitted):</p>
  
  <pre><code>{
    "name": "myshared",
    "scripts": {
    },
    "dependencies": {
    },
    "devDependencies": {
    },
    "engines": {
      "node": "8"
    },
    "private": true,
    "version": "0.0.1"
  }
  </code></pre>
  
  <p>My firebase functions package.json (extraneous details omitted):</p>
  
  <pre><code>{
    "name": "functions",
    "scripts": {
    },
    "dependencies": {
      "myshared": "file:../shared",
    },
    "devDependencies": {
    },
    "engines": {
      "node": "8"
    },
    "private": true
  }
  </code></pre>
  
  <p>When I try to deploy with:</p>
  
  <pre><code>firebase deploy --only functions
  </code></pre>
  
  <p>It's telling me it can't load the module:</p>
  
  <pre><code>Function failed on loading user code. Error message: Code in file index.js can't be loaded.
  Did you list all required modules in the package.json dependencies?
  </code></pre>
  
  <p>And I don't think the issue is how I export/imported my code- but just in case:
  The export:</p>
  
  <pre><code>exports.myFunc = () =&gt; { some code };
  </code></pre>
  
  <p>The import (functions/index.js)</p>
  
  <pre><code>const myFunc = require('myshared');
  </code></pre>
  
  <p>And in my react code:</p>
  
  <pre><code>import { myFunc } from 'myshared';
  </code></pre>
  
  <p>So far the searching I've done hasn't yielded anything that works. Someone did mention entering the shared module path in firebase.json, but I couldn't find any details (including in the firebase docs) that show what that would look like. Thanks for any tips to get this going.</p>