When I try to deploy my functions, firebase complains about this:
const admin = require('firebase-admin');
const functions = require('firebase-functions');
const C = require('../both/constants.js');
exports.myFunc = functions.database.ref('aRef').onCreate((event) => {
// blah blah
}
Error: Error parsing triggers: Cannot find module '../both/constants.js'
But not this:
const admin = require('firebase-admin');
const functions = require('firebase-functions');
// This is the invite that goes to organizations.
exports.myFunc = functions.database.ref('aRef').onCreate((event) => {
const C = require('../both/constants.js');
}
Why is that?
Update: It would appear this happens because the function will not look for the dependency until runtime. This is of course an issue because the dependencies are still needed. I should mention my project looks like this:
both
constants.js
functions
index.js
myFunc.js
Update 2 Now that I'm moving my stack entirely to Firebase functions, I got back to working on this issue again. The module needs to be published for it to work within the function. Just FYI for anyone who happens upon this psot.
Putting your functions code anywhere other than the functions
directory is not supported. Note then when you deploy it says this:
i functions: preparing functions directory for uploading...
i functions: packaged functions (34.06 KB) for uploading
✔ functions: functions folder uploaded successfully
It is only looking at functions
and all of its sub-folders.
If I deploy code that requires code outside of functions
, I also see a "module not found" error in the console.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With