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.
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
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.
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 , 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 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.