Unable to launch Google Cloud Functions when using multiple files

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.

Answer №1

To resolve the issue, one approach is to include the following code snippet in the tsconfig.json file:

"exclude": [
    "node_modules"
]

However, I am still uncertain about the underlying rationale for why this solution is effective.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Strategies for securing Firebase storage in Next.js without relying on Firebase authentication

Utilizing firebase storage for file uploads on my next.js page. Users complete a form and the files are uploaded to firebase storage (using a different database). I am seeking a way to restrict file uploads only within this post request. import React, { u ...

typescript scrolling location

In my Angular UI code, I have a component class that includes the following structure: app.component.html //... <div class="banner"> <p-dialog [(visible)]="displayCOI" styleClass="coiDialog" [contentStyle]=" ...

Ways to display components within the content section of the home component rather than on a distinct page using Angular 5

I recently started working with Angular 5 and I'm encountering an issue with component routing. My goal is to have the app display a login screen when a user first opens it (the login screen should take up the entire browser window). Once the user su ...

The tsconfig.json file does not support the path specified as "@types"

Having set up multiple absolute paths for my Next.js application, I encounter an issue where importing a component from the absolute path results in something like "../componentName" instead of "@components/componentName" when I am inside another folder. T ...

Automating email testing for Azure Graph-built applications: A step-by-step guide

I am exploring options to streamline the email testing process for an application developed with Azure Graph integration. Currently, I am leveraging playwright and typescript for other testing purposes within the application. One of the key functionaliti ...

What is the appropriate interface for determining NavLink isActive status?

In the process of crafting a "dumb" component using NavLink, I am defining the props interface for this component. However, I encountered an issue when trying to include isActive in the interface. It's throwing errors. I need guidance on how to prope ...

What is the reason for my Angular2 application not being able to locate my model?

An error occurred: XHR error (404) loading Access the Plnkr link here: https://plnkr.co/edit/gwa3NWArtWK0wjf2jr2h?p=preview I have created a file named models/home.ts https://i.sstatic.net/FQlgi.png The file includes: export function homeData() { re ...

Is there a way to safeguard against accidental modifications to MatTab without prior authorization?

I need to delay the changing of the MatTab until a confirmation is provided. I am using MatDialog for this confirmation. The problem is that the tab switches before the user clicks "Yes" on the confirmation dialog. For instance, when I try to switch from ...

Guide to Setting Up Infinite Scroll with Next JS SSG

I recently built a markdown blog using the Next Js documentation and incorporated Typescript. When trying to retrieve a list of blog posts, I utilized getStaticProps as recommended in the documentation. However, my attempts with certain npm packages were u ...

how to adjust the width of a window in React components

When attempting to adjust a number based on the window width in React, I encountered an issue where the width is only being set according to the first IF statement. Could there be something wrong with my code? Take a look below: const hasWindow = typeof ...

Is there a way to modify the button exclusively within the div where it was pressed?

I plan to incorporate three buttons in my project (Download, Edit, and Upload). Upon clicking the Download button, a function is triggered, changing the button to Edit. Clicking the Edit button will then change it to Upload, and finally, clicking the Uplo ...

Unable to trigger dispatchEvent on an input element for the Tab key in Angular 5

In my pursuit of a solution to move from one input to another on the press of the Enter key, I came across various posts suggesting custom directives. However, I prefer a solution that works without having to implement a directive on every component. My a ...

Defining TypeScript return types according to input parameters

Within this snippet, the data type of v1 is currently set as BehaviorSubject<string | number>, while the type of v2 is defined as an empty object {}. My goal is to alter the data type of v1 to be BehaviorSubject<string>, and have the type of v ...

Is there a way to use a single url in Angular for all routing purposes

My app's main page is accessed through this url: http://localhost:4200/ Every time the user clicks on a next button, a new screen is loaded with a different url pattern, examples of which are shown below: http://localhost:4200/screen/static/text/1/0 ...

Issues with Angular not reflecting data changes in the view after updates have occurred

I have a setup with two components. One is responsible for creating new data entries, while the other one is in charge of listing all the data stored in a database. The issue I'm facing is that even though the creation component successfully adds new ...

Tips for showcasing information of a particular child in a database

I am currently immersed in a project that involves Cloud 9 and Ionic, with a Firebase database at its core. My main challenge lies in referencing the specific details of a particular vehicle (as per the database layout) and then displaying this information ...

Firestore experiences updates from Cloud Functions with a delay

Just starting out with cloud functions and need some help! I want to disable my targets after a countdown ends. The function I have works correctly, but it updates the status after 3 minutes once the function has finished running. What could I be missing ...

The form validation feature in Element UI is having issues when used with the Vue 2 Composition API

I am currently developing a form that utilizes element UI's form validation within the vue 2 composition API environment. This form includes a table nested inside, making its structure somewhat complex. ... <div> <el-form ref=" ...

Learning how to implement a real-time database event listener with Firebase in React Native

I am facing an issue with adding an event listener to my react native application. The listener is supposed to trigger when there is a change, but it only works after refreshing the app. I believe the problem lies in how I've set up the event listener ...

Using the prop callback in a React test renderer does not trigger updates in hooks

I am currently exploring ways to effectively test a React function component that utilizes hooks for state management. The issue I am encountering revolves around the onChange prop function not properly updating the state value of my useState hook. This in ...