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:
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:
Using Relative Paths (./services/handle-report-service😞
Using path.join() and path.resolve() with __dirname:
Testing process.cwd():
Double-checking the folder structure:
The services/handle-report-service.js file is present locally and is deployed as part of the extension.
Checking deployment settings and logs:
I reviewed the deployment logs, but nothing indicates why this file isn't being found.
It doesn't look like we've found a solution to this yet; however, let's tag in some Top Contributors to see if they have any ideas -- Hi @LauraMarie@ArisudanTiwari and @kosalaindrasiri. Do you have any suggestions?
Thank you!
Cassie, Community Manager
Loop Marketing is a new four-stage approach that combines AI efficiency and human authenticity to drive growth.
HubSpot UI Extension | Serverless Function Fails to Find Local Module After Deployment in HubSpot UI
Hi, Thanks for your response.
It is 2025.1 but I eventually found a hubspot article saying the local includes are not supported with Hubspot's serverless functions so I just have to cut and paste common routines into each function
HubSpot UI Extension | Serverless Function Fails to Find Local Module After Deployment in HubSpot UI
Hi @kennedyp Can you please check if anyone has an answer for this? I keep receiving this error for multiple projects and have no idea how to fix it. The provide answers up to now are not correct!
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:
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.