Uncaught ReferenceError: document is not defined

For Workes & Pages, what is the name of the domain?

localhost

What is the error number?

none

What is the error message?

Uncaught ReferenceError: document is not defined

What is the issue or error you’re encountering

Can’t start the cloudflare worker on local machine

What steps have you taken to resolve the issue?

I’m developing cloudflare worker which will be interacting with Azure Tables SDK:

I’m using honojs and typescript.

In order to connect to Azure Cosmos DB Table API I need to create table client:
const tableClient = TableClient.fromConnectionString(this.db_connection_string, this.db_tabel_name);

After adding this code, cloudflare worker can’t start on a local machine after calling ‘npm run dev’ and throws the error:
[ERROR] service core:user:electro-backend: Uncaught ReferenceError: document is not defined

I created another solution with node.js and honojs but without cloudflare worker and such stack working fine, without any errors.

What’s happening here?

Appreciate the help.

Any updates on this topic are highly appreciated!

Support?

What is the name of the domain?

localhost

What is the issue you’re encountering

Support is not responding

What steps have you taken to resolve the issue?

Created a support ticket on July 23rd. I have a Pro plan. No response since then!
How to get any feedback from the support?

Anyone?

Welcome to the Community.

What is the ticket about? And could you please share the ticket number?

Multiple tickets with Support slow down the reply for you @services86 and everyone else.

I am not sure Support can help troubleshoot your workers code and you may want to ask the team on discord, Cloudflare Developers

2 Likes

Have you tried raising this in the Cloudflare Developers discord community? The #workers-help and #coding-help channels would be good places to ask a question like this. https://discord.gg/cloudflaredev

2 Likes

I’m new to the cloudflare, that’s why do not know your policy yet where to write what.

I created the topic on the cloudflare community forum and was waiting for several days without any response.

When I bought a support plan in order to create a support ticket, which is obvious I think.
For almost 2 weeks no response from support on my ticket.

I don’t know how much time should I wait more, but one person suggested me to write to discord, which I did and got reply it’s not a cloudflare case.

But now it’s the matter of principle: I paid money and never got any response.

I’m afraid if I start developing on your platform and something happens again - I will never get any help.

case number: 00987296

You posted your ticket on the Discord server, not the actual issue. As @cloonan mentioms, Support are unlikely to be able to help with code issues as that is outside the scope of the support.

2 Likes

I don’t understand, cloudflare platform provides services for developers and not able to help if some code is not working on this service? Really?

You’re charging the same price for the support as Microsoft does. But Microsoft responses within hours if ticket created and even meets you online using Teams and helps.

Who is responsible if platform is not working as expected? Where to get help? From community?
Why do you advertise that for the money I will have the ability to directly talk to support?

Up until now there is no answer in my ticket! It is still open!

How do I get my refund in this case if support is not answering inside ticket and I need to search for the help inside community for free?

Apologies for reviving an old thread, but thought I’d post here for anyone else who ran into the same problem.

I think the simple answer is that Azure table client SDK uses Node APIs which are not compatible with cloudflare workers. As per the documentation:

Many npm packages rely on APIs from the Node.js runtime :arrow_upper_right:, and will not work unless these Node.js APIs are available.

Specifically, looking through the Azure tableclient code, we can see it requires document:

// node_modules/@azure/core-xml/dist/browser/xml.js
if (!document || !DOMParser || !Node || !XMLSerializer) {
throw new Error(`This library depends on the following DOM objects: ["document", "DOMParser", "Node", "XMLSerializer"] to parse XML, but some of these are undefined. You may provide a polyfill to make these globally available in order to support your environment. For more information, please refer to https://aka.ms/azsdk/js/web-workers. `);
}

I tried following the instructions in that microsoft link. In their example (azure-sdk-for-js/samples/web-workers/README.md at main · Azure/azure-sdk-for-js · GitHub), they use jsdom to polyfill the missing apis, but I couldn’t get it to work (ultimately fails on Uncaught ReferenceError: FinalizationRegistry is not defined).

I then tried creating a hono project targetting node instead of cloudflare workers.
It ran fine. (i.e. follow the instructions at Node.js - Hono) and then install @azure/data-tables and create your client in the code - it works.

Quite a bummer, I was hoping to convert my APIs to cloudflare workers, but looks like I’ll be sticking with docker containers.

therealjordanlee you’re absolutely correct. Not supported node.js is the main issue.

Microsoft confirmed this after i turned to them for the help.

By the way, try Convex instead, if it will suits your needs. It supports node.js