CMS Development

MAsghari
Participant | Elite Partner
Participant | Elite Partner

HubSpot UI Extension | Serverless Function Fails to Find Local Module After Deployment in HubSpot UI

Hi There,

I'm deploying a custom UI Extension in HubSpot that includes serverless functions. Locally, everything works fine, but once I deploy, I encounter the following error:

 

 

{
    "status": "error",
    "message": "The serverless function 'handle-report' failed to execute: Cannot find module './services/handle-report-service'\nRequire stack:\n- /var/task/test.js\n- /var/task/hubspotHandler.js\n- /var/runtime/index.mjs."
}

 

 

I'm attempting to require a local module from in 'handle-report' which is a serverless function:

 

 

// Services
const HandleReportService = require('./services/handle-report-service');

exports.main = async (context = {}) => {
  -----
}

 

In local development, this works perfectly, and the module is found as expected. However, once the extension is deployed in the HubSpot environment, using 'hs project upload' the serverless function fails with a "Cannot find module" error.

 

What I've Tried:

  1. Using Relative Paths (./services/handle-report-service😞

  2. Using path.join() and path.resolve() with __dirname:

  3. Testing process.cwd():

  4. Double-checking the folder structure:

    • The services/handle-report-service.js file is present locally and is deployed as part of the extension.
  5. Checking deployment settings and logs:

    • I reviewed the deployment logs, but nothing indicates why this file isn't being found.

 Can you help me to understand the problem?

0 Upvotes
4 Replies 4
MAsghari
Participant | Elite Partner
Participant | Elite Partner

HubSpot UI Extension | Serverless Function Fails to Find Local Module After Deployment in HubSpot UI

Hi There!

Any feedback/solution for  this?

 

0 Upvotes
MAsghari
Participant | Elite Partner
Participant | Elite Partner

HubSpot UI Extension | Serverless Function Fails to Find Local Module After Deployment in HubSpot UI

Hi @kennedyp 

Can you please check this question and send it to one your specialist to check!

I'd appreciate if @zach_threadint can take a look at this!

0 Upvotes
KhushbooRevOps
Participant

HubSpot UI Extension | Serverless Function Fails to Find Local Module After Deployment in HubSpot UI

Hi @MAsghari,

The issue likely stems from how HubSpot handles paths in the serverless environment after deployment. In a serverless setup, the directory structure may differ from local development, so relative paths don't always behave as expected.

Here’s what you can do:

1. Check that the filename and the import path match exactly, including case sensitivity. Serverless environments may be stricter about this than local ones.


2. Try switching from relative paths (./services/handle-report-service) to absolute paths by using path.resolve() to ensure the correct module path:

const path = require('path');
const HandleReportService = require(path.resolve(__dirname, './services/handle-report-service'));

3. Verify that the services/handle-report-service.js file is included in the build when you deploy the project using hs project upload. Sometimes, files may not be uploaded if excluded in deployment settings.


4. If the issue persists, try cleaning the project (delete build artifacts) and re-deploying it using hs project upload.

This should help resolve the path issue in the serverless environment.

 

I hope it helps, let me know if you need to talk!

Khushboo Pokhriyal

Growth & Operations

GroRapid Labs

LinkedIn | 9315044754 | Email | Website



0 Upvotes
MAsghari
Participant | Elite Partner
Participant | Elite Partner

HubSpot UI Extension | Serverless Function Fails to Find Local Module After Deployment in HubSpot UI

Hi, Thanks for your response,

I Already tried all of them, none of them will work!

0 Upvotes