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"
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
2 Replies
kafka🦴
kafka🦴•13mo ago
I also have this problem. I want to be able to move my sveltekit project from vercel to pages, but just isn't working as I have tried multiple different polyfills and approaches. Pages are not that useful in a node.js project if you cannot use some of the node core packages.
sten
sten•13mo ago
Have anyone gotten this to work with polyfills, like ever? I think easiest route for you is to use the http API and not rely on googleapi library
Want results from more Discord servers?
Add your server