When attempting to deploy some function scripts to Firebase Functions, I encountered an error. The error message reads:
Function failed on loading user code. Error message: Code in file lib/index.js can't be loaded.
Did you list all required modules in the package.json dependencies?
Detailed stack trace: Error: Cannot find module './helloWorld'
I initialized the project using firebase init function
and created two files: index.ts
and helloWorld.ts
. Deployment is successful when all the code is placed in a single file index.ts
. However, splitting the code into both files results in the aforementioned error.
I have confirmed that TypeScript is transpiling correctly, generating the corresponding files in the lib/
folder.
Despite searching online, I have been unable to find a similar issue.
File: index.ts
export * from './helloWorld';
File: helloWorld.ts
import * as functions from "firebase-functions";
export const helloWorld = functions.https.onRequest((request, response) => {
response.send("Hello World!");
});
Transpiled files:
File: index.js
"use strict";
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
Object.defineProperty(exports, "__esModule", { value: true });
__export(require("./helloWorld"));
//# sourceMappingURL=index.js.map
File: helloWorld.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const functions = require("firebase-functions");
exports.helloWorld = functions.https.onRequest((request, response) => {
response.send("Hello World!");
});
//# sourceMappingURL=helloWorld.js.map
I suspect that Firebase functions may not be deploying helloWorld.ts
or if it is, failing to transpile it into helloWorld.js
, causing issues with locating the module ./helloWorld
within index.js
.