Description
Bug Report
Current behavior
I'm using Azure Tables with winston as a logging solution on a nextjs app. Everything works fine everywhere,
except when the logger is called from the middleware; Switching to the experimental nodejs runtime on middleware solved it.
The issue is that when inserting on an Azure Table, the library eventually calls a method from its core-xml
dependency. On the nodejs runtime, it correctly resolves the -- IIUC -- esm
dependency, but on the edge, it resolves the browser version, which makes these checkes:
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. `,
);
}
Which leads to this error being thrown:
ReferenceError: document is not defined
at (file:///project/workspace/reproduction-app/node_modules/ (azure/core-xml/dist/browser/xml.js:4)
at eval (webpack-internal:///(middleware)/./node_modules/@azure/core-xml/dist/browser/xml.js:10:1)
at (middleware)/./node_modules/@azure/core-xml/dist/browser/xml.js (file:///project/workspace/reproduction-app/.next/server/middleware.js:821:1)
at webpack_require (file:///project/workspace/reproduction-app/.next/server/edge-runtime-webpack.js:37:33)
at fn (file:///project/workspace/reproduction-app/.next/server/edge-runtime-webpack.js:268:21)
at eval (webpack-internal:///(middleware)/./node_modules/@azure/core-xml/dist/browser/index.js:8:65)
at (middleware)/./node_modules/@azure/core-xml/dist/browser/index.js (file:///project/workspace/reproduction-app/.next/server/middleware.js:799:1)
at webpack_require (file:///project/workspace/reproduction-app/.next/server/edge-runtime-webpack.js:37:33)
at fn (file:///project/workspace/reproduction-app/.next/server/edge-runtime-webpack.js:268:21)
at eval (webpack-internal:///(middleware)/./node_modules/@azure/data-tables/dist/browser/TableServiceClient.js:9:73)
at (middleware)/./node_modules/@azure/data-tables/dist/browser/TableServiceClient.js (file:///project/workspace/reproduction-app/.next/server/middleware.js:854:1)
Repro: https://codesandbox.io/p/live/7477c39c-1b02-4285-a5bf-7db900531eb0
Expected behavior/code
The esm
version is used, just like on the nodejs runtime, and everything works.
Possible solution
If only I understood more about this 😅
One thing I'm not sure is whether the responsibility of fixing this is on the Edge Runtime or on the azure lib. On another issue like this one, a maintainer from the azure-sdk repo talked about something similar and seemed to indicate it is something they could fix; On the other hand, on a comment right above the OP said that supabase fixed the issue on their side.
Also, independently of whether or not azure can fix this on their side, and even though I've found a workaround with the currently experimental nodejs runtime for middleware, my main reason for opening this issue is whether there's a more fundamental issue that's responsible for the runtime tripping the package resolution.
Additional context/screenshots
n/a