Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Javascript constant is not recognized in my .sqlx file

Hello all,

I have been trying to figure out this error message below. I am following the Dataform documentation but somehow keep getting this error when I try to use a .js constant for the project name for my table name in the .sqlx file.

My .js file is at includes/constants.js and this is the content:

 

const load_project = "project_name";
module.exports = { load_project };

Screenshot 2024-12-04 at 17.14.49.png

Funny thing is that, this code was working fine and started throwing this error today when I started working on this code further. I found similar question in stackoverflow which was also not answered.

Solved Solved
1 7 332
1 ACCEPTED SOLUTION

Are you sure that you have a constant `load_project` defined? `Access Denied: Table` is a misleading error message since `undefined:heroku_coachdb.attendees` is not a real table because `undefined` is not a real project.

If you are sure that you got the spelling right, I would suggest you recreate the constant in a new line and delete the previous line. It's a weird bug but I've seen these things happen especially when copy-pasting.

View solution in original post

7 REPLIES 7

You are right; this should be working. Did you make any recent changes to your workflow_settings.yaml? If you did, try to press "INSTALL PACKAGES" again. If error persists, can you send a screenshot of your workspace directory structure?

Thanks for the reply. Though I hadnt done any changes to the .yaml file, I installed the packages again but the problem persists. Is this screenshot useful?
I am only using the slowly changing dimensions package from Dataform additionally.

Screenshot 2024-12-05 at 09.37.01.png

The only plausible explanation I can think of is you got the spelling of your constant wrong. Although your example shows the same spelling in your constants file and your sqlx file, it may have been changed accidentally while doing other edits.

Hi @kccanut,

Welcome to the Google Cloud Community!

You can check the following that might help resolve the error you're encountering:

  • Make sure your Dataform project's configuration (often a dataform.json or similar file) is set up correctly to include the includes directory.  This often involves a projectRoot setting to point to the directory containing your includes folder.  For example: json
{

  "projectRoot": "./" //Or the path to your includes directory, depending on your setup

}
  • Regarding the 'Access Denied' error message you encountered, the most likely cause is that the service account used by Dataform does not have the necessary roles and permissions to access the specified BigQuery dataset and table. The service account will need all of these roles to ensure proper access:
    • roles/bigquery.dataViewer
    • roles/bigquery.dataEditor
    • roles/bigquery.dataOwner
  • Ensure you have a compatible and correctly installed version of Dataform. 
  • Ensure your Dataform configuration doesn’t have any changes especially on the location.
  • If there are changes, try rebuilding your Dataform project and redeploying your changes. Run dataform comply and then dataform deploy to redeploy your updates.

I hope the above information is helpful.

Thanks for your reply. I think I am quite new thus couldnt follow your first point. I have a workflow_settings.yaml file and use Dataform 3.0.8 (the latest version) When I add projectRoot to the yaml file, it does not get recognized. I get this error:

"Uncaught ReferenceError: Workflow settings error: Unexpected property "projectRoot", or property value type of "string" is incorrect. See https://dataform-co.github.io/dataform/docs/configs-reference#dataform-WorkflowSettings for allowed properties."

The service account has the bigquery roles you mentioned. I use databaselocation = eu. So other points look fine to me.

Lastly, I can actually call the javascript variables in my code. Here is an example where it works with one instance and doesnt work with the other one.

Screenshot 2024-12-11 at 14.28.58.png

Are you sure that you have a constant `load_project` defined? `Access Denied: Table` is a misleading error message since `undefined:heroku_coachdb.attendees` is not a real table because `undefined` is not a real project.

If you are sure that you got the spelling right, I would suggest you recreate the constant in a new line and delete the previous line. It's a weird bug but I've seen these things happen especially when copy-pasting.

When I recreated the constant in a new line with just copy pasting, it worked. Wow! Thanks a lot!