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

Hi I have to post this question again, since my last post didn’t get enough attantion and response!

I am developing an applicatoin with HubSpot UI Extension and I receive this error. Try all different possible solutions and unfortuntely none of them work. This question truely need an attention from HubSpot community!

Here is the error log:

fetchProperties serverless function failed due to this error:

2024-11-25T16:50:00.423Z ERROR - Error: Cannot find module './connectors/hubspot/factory/hubspot-connector.factory'
Require stack:
- /var/task/test.js
- /var/task/hubspotHandler.js
- /var/runtime/index.mjs
 at Module._resolveFilename (node:internal/modules/cjs/loader:1140:15)
 at Module._load (node:internal/modules/cjs/loader:981:27)
 at Module.require (node:internal/modules/cjs/loader:1231:19)
 at require (node:internal/modules/helpers:177:18)
 at Object.<anonymous> (/var/task/test.js:13:37)
 at Module._compile (node:internal/modules/cjs/loader:1364:14)
 at Module._extensions..js (node:internal/modules/cjs/loader:1422:10)
 at Module.load (node:internal/modules/cjs/loader:1203:32)
 at Module._load (node:internal/modules/cjs/loader:1019:12)
 at Module.require (node:internal/modules/cjs/loader:1231:19) {
 code: 'MODULE_NOT_FOUND',
 requireStack: [
 '/var/task/test.js',
 '/var/task/hubspotHandler.js',
 '/var/runtime/index.mjs'
 ]
}

Here is my file hierachy:

- fetchProperties.js

- connectors

 - hubspot

 - factory

 - hubspot-connector.factory.js

As you see I am trying to make an import from “hubspot-connector-factory.js” file inside my serverless function “fetchProperties.js” and seems the Node.js runtime can’t understand this “relative path”. Has anyone confront with this problem before? what is the best soltuion/practice here?

Hey, @MAsghari :waving_hand: Thanks for your question. Please be cautious about reposting the same question multiple times. I know it’s challenging when you are not getting responses, especially when you are stuck. It’s important to note that our community is founded on peer-to-peer support and is made of expert volunteers who generously share their knowledge. While we would love to get answers for every query, there is no guarantee that someone will have the solution you are after. In my experience, if a member doesn’t have a solid answer, they are more likely to not respond rather than give an incomplete or incorrect reply.

Here’s are some troubleshooting steps (I used ChatGPT to help me organize my notes):

  • Double-check your case sensitivity — make sure your file and folder names match exactly in your deployed environment
  • Verify your Relative Path — Confirm the path ./connectors/hubspot/factory/hubspot-connector.factory is correct from fetchProperties.js.
  • make sure your hubspot-connector.factory.js is included in the deployment. I’d double-check .gitignore or .npmignore for exclusions
  • You can try replacing relative path imports with absolute paths — path.resolve
  • Double-check your Node version matches in your dev environment and local version
  • Update your Deployment config to explicitly include your required files — e.g., serverless.yml
  • Try using Docker or a case-sensitive file system to reproduce the deployment environment

Hey @Teun @ChrisoKlepke @evaldas, do you have any other troubleshooting suggestions?

Thanks! — Jaycee