Local dev server doesn't see secrets.env file (Hubspot UI extension development)

Hello everyone. I’m working on a CRM Card extension using the new Hubspot UI Extensions beta. I keep getting the following error: “Error: Cannot fetch CRM object properties without a HubSpot API access token. This is not a problem with your code. Please copy the access token for your app at https://app.hubspot.com/private-apps/******* and save it in an ‘.env’ file in the ‘app.functions’ folder.”


Console error screenshot

I’ve followed exactly the instructions at Serverless functions reference (projects) - HubSpot docs and have my secrets in a “secrets.env” file in the app.functions directory:


secrets.env


Project structure with secrets.env highlighted in blue

Here’s where the error is being thrown (line 5):


Code throwing the error (line 5)

The log on line 4 also shows the token as undefined.

I’m completely at a loss here. If anyone has ideas for how I can get this up and running I’d really appreciate it!

Hello everyone. I’m working on a CRM Card extension using the new Hubspot UI Extensions beta. I keep getting the following error: “Error: Cannot fetch CRM object properties without a HubSpot API access token. This is not a problem with your code. Please copy the access token for your app at https://app.hubspot.com/private-apps/******* and save it in an ‘.env’ file in the ‘app.functions’ folder.”

I’ve followed exactly the instructions at Serverless functions reference (projects) - HubSpot docs and have my secrets in a “secrets.env” file in the app.functions directory:


secrets.env


Project structure with secrets.env highlighted in blue

Here’s where the error is being thrown (line 5):

The log on line 4 also shows the token as undefined.

I’m completely at a loss here. If anyone has ideas for how I can get this up and running I’d really appreciate it!

While looking for answers I did stumble across this post which said to use .env files you need the dotenv-webpack npm package. I installed that and gave that a try as well but I’m running into the same error.

For environment context, I’m running Windows 10 and the project is setup on Node v18.17.1 with Hubspot api client 7.2.0

I figured it out! Despite the examples showing files called “secrets.env” it appears the fileloader in the secrets.js file at @hubspot\cli\node_modules\@hubspot\app-functions-dev-server\dist\secrets.js is missing wildcard indicators, so it will only accept “.env” as the file name.

I renamed the file to “.env” and it started successfully pulling the secrets, but then threw an error that the authentication method wasn’t found. This is because executor.js (same path as the secrets.js file) only runs when the call to a serverless function occurs. This means (again, contrary to the documentation and examples) that you can’t instantiate the hubspot client outside of the exported function in each serverless js file because the secrets haven’t been committed to environment variables yet. Re-instantiating the hsClient within each function in the files seems to have resolved this. I’ll accept this as the answer and hope that better documentation is released for the UI Extensions in the future.