SvelteKit build error: Node modules could not be resolved

Hi, I have a SvelteKit project with
googleapis
package installed. I tried deploying it to Pages with cloudflare adapter but the build failed with errors like the following:
  The package "stream" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.

06:47:24.269    error during build:
06:47:24.269    Error: Build failed with 53 errors:
06:47:24.269    node_modules/agent-base/dist/src/index.js:5:25: ERROR: Could not resolve "events"
06:47:24.270    node_modules/buffer-equal-constant-time/index.js:3:21: ERROR: Could not resolve "buffer"
06:47:24.270    node_modules/gaxios/build/src/gaxios.js:20:24: ERROR: Could not resolve "https"
06:47:24.270    node_modules/gaxios/build/src/gaxios.js:22:46: ERROR: Could not resolve "querystring"
06:47:24.270    node_modules/gaxios/build/src/gaxios.js:24:22: ERROR: Could not resolve "url"

I have googled around and deduce that the problem is these core node modules need to be polyfilled (cmiiw). I have tried various polyfilling packages that I could find on Google (
vite-plugin-node-polyfills
,
@esbuild-plugins/node-globals-polyfill
,
@esbuild-plugins/node-modules-polyfill
), however none seems to be solving the problem. Is there any solution for this? I use
googleapis
to utilize the Google Sheets API to retrieve data from a spreadsheet
Was this page helpful?