kit
kit copied to clipboard
Builds break after upgrading to SvelteKit 2
Describe the bug
I have a project using svelte kit with Drizzle ORM and Supabase. The whole project is open source and can be found here. I recently updated everything to sveltekit 2, and since then my builds have been broken.
Reproduction
https://github.com/jhechtf/vercel-adapter-breaking - only using PNPM
https://github.com/sungmanito/mono/commit/5cc6e7326c28ab95ae363e4aad59415077adafce is where pnpm build stops working, giving these errors
> Using @sveltejs/adapter-vercel
X [ERROR] Top-level await is not available in the configured target environment ("es2020")
.svelte-kit/output/server/chunks/client.js:161:0:
161 │ await pool.connect();
╵ ~~~~~
X [ERROR] Could not resolve "net"
node_modules/.pnpm/[email protected]/node_modules/pg/lib/connection.js:3:18:
3 │ var net = require('net')
╵ ~~~~~
The package "net" 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.
X [ERROR] Could not resolve "events"
node_modules/.pnpm/[email protected]/node_modules/pg/lib/client.js:3:27:
3 │ var EventEmitter = require('events').EventEmitter
╵ ~~~~~~~~
The package "events" 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.
X [ERROR] Could not resolve "events"
node_modules/.pnpm/[email protected][email protected]/node_modules/pg-pool/index.js:2:29:
2 │ const EventEmitter = require('events').EventEmitter
╵ ~~~~~~~~
The package "events" 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.
X [ERROR] Could not resolve "events"
node_modules/.pnpm/[email protected]/node_modules/pg/lib/native/client.js:12:27:
12 │ var EventEmitter = require('events').EventEmitter
╵ ~~~~~~~~
The package "events" 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.
X [ERROR] Could not resolve "events"
node_modules/.pnpm/[email protected]/node_modules/pg/lib/connection.js:4:27:
4 │ var EventEmitter = require('events').EventEmitter
╵ ~~~~~~~~
The package "events" 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.
X [ERROR] Could not resolve "assert"
node_modules/.pnpm/[email protected]/node_modules/pg-protocol/dist/parser.js:9:41:
9 │ const assert_1 = __importDefault(require("assert"));
╵ ~~~~~~~~
The package "assert" 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.
X [ERROR] Could not resolve "util"
node_modules/.pnpm/[email protected]/node_modules/pg/lib/native/client.js:13:19:
13 │ var util = require('util')
╵ ~~~~~~
The package "util" 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.
X [ERROR] Could not resolve "net"
node_modules/.pnpm/[email protected]/node_modules/pg/lib/stream.js:6:22:
6 │ const net = require('net')
╵ ~~~~~
The package "net" 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.
X [ERROR] Could not resolve "tls"
node_modules/.pnpm/[email protected]/node_modules/pg/lib/stream.js:21:20:
21 │ var tls = require('tls')
╵ ~~~~~
The package "tls" 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.
X [ERROR] Could not resolve "path"
node_modules/.pnpm/[email protected]/node_modules/pgpass/lib/index.js:3:19:
3 │ var path = require('path')
╵ ~~~~~~
The package "path" 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.
X [ERROR] Could not resolve "dns"
node_modules/.pnpm/[email protected]/node_modules/pg/lib/connection-parameters.js:3:18:
3 │ var dns = require('dns')
╵ ~~~~~
The package "dns" 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.
X [ERROR] Could not resolve "events"
node_modules/.pnpm/[email protected]/node_modules/pg/lib/native/query.js:3:27:
3 │ var EventEmitter = require('events').EventEmitter
╵ ~~~~~~~~
The package "events" 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.
X [ERROR] Could not resolve "events"
node_modules/.pnpm/[email protected]/node_modules/pg/lib/query.js:3:33:
3 │ const { EventEmitter } = require('events')
╵ ~~~~~~~~
The package "events" 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.
X [ERROR] Could not resolve "crypto"
node_modules/.pnpm/[email protected]/node_modules/pg/lib/crypto/utils-legacy.js:5:27:
5 │ const nodeCrypto = require('crypto')
╵ ~~~~~~~~
The package "crypto" 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.
X [ERROR] Could not resolve "crypto"
node_modules/.pnpm/[email protected]/node_modules/pg/lib/crypto/utils-webcrypto.js:1:27:
1 │ const nodeCrypto = require('crypto')
╵ ~~~~~~~~
The package "crypto" 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.
X [ERROR] Could not resolve "fs"
node_modules/.pnpm/[email protected]/node_modules/pgpass/lib/index.js:4:17:
4 │ , fs = require('fs')
╵ ~~~~
The package "fs" 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.
X [ERROR] Could not resolve "fs"
node_modules/.pnpm/[email protected]/node_modules/pg-connection-string/index.js:76:77:
76 │ const fs = config.sslcert || config.sslkey || config.sslrootcert ? require('fs') : null
╵ ~~~~
The package "fs" 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.
X [ERROR] Could not resolve "util"
node_modules/.pnpm/[email protected]/node_modules/pg/lib/native/query.js:4:19:
4 │ var util = require('util')
╵ ~~~~~~
The package "util" 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.
X [ERROR] Could not resolve "path"
node_modules/.pnpm/[email protected]/node_modules/pgpass/lib/helper.js:3:19:
3 │ var path = require('path')
╵ ~~~~~~
The package "path" 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.
X [ERROR] Could not resolve "stream"
node_modules/.pnpm/[email protected]/node_modules/pgpass/lib/helper.js:4:21:
4 │ , Stream = require('stream').Stream
╵ ~~~~~~~~
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.
X [ERROR] Could not resolve "util"
node_modules/.pnpm/[email protected]/node_modules/pgpass/lib/helper.js:6:19:
6 │ , util = require('util')
╵ ~~~~~~
The package "util" 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.
X [ERROR] Could not resolve "stream"
node_modules/.pnpm/[email protected]/node_modules/split2/index.js:19:30:
19 │ const { Transform } = require('stream')
╵ ~~~~~~~~
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.
X [ERROR] Could not resolve "buffer"
node_modules/.pnpm/[email protected]/node_modules/safe-buffer/index.js:3:21:
3 │ var buffer = require('buffer')
╵ ~~~~~~~~
The package "buffer" 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.
Logs
N/A, this occurs during build time. `pnpm dev` works just fine.
System Info
System:
OS: Windows 10 10.0.19045
CPU: (16) x64 AMD Ryzen 7 3700X 8-Core Processor
Memory: 14.56 GB / 31.93 GB
Binaries:
Node: 20.10.0 - C:\Program Files\nodejs\node.EXE
Yarn: 1.22.5 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
npm: 10.2.3 - C:\Program Files\nodejs\npm.CMD
pnpm: 8.12.1 - ~\AppData\Roaming\npm\pnpm.CMD
Browsers:
Chrome: 120.0.6099.110
Edge: Chromium (120.0.2210.77)
npmPackages:
@sveltejs/adapter-auto: ^3.0.0 => 3.0.0
@sveltejs/adapter-vercel: ^3.1.0 => 3.1.0
@sveltejs/kit: ^2.0.3 => 2.0.3
@sveltejs/vite-plugin-svelte: ^3.0.1 => 3.0.1
svelte: ^4.2.8 => 4.2.8
vite: ^5.0.10 => 5.0.10
### Severity
blocking all usage of SvelteKit
### Additional Information
On my local I've moved from using the `postgres` package to the `pg` package for connecting Drizzle to my database. Pg requires the `.connect()` to work. In a PR (https://github.com/sungmanito/mono/pull/19) I reverted the commit that updated to sveltekit 2 and the vercel deployment works correctly, even with the `await client.connect();`

Preview build was tested and works as expected.
You need to provide a confined reproducible repl, you can't just provide your entire app and expect the svelte team to troubleshoot for you 😢
You've even said yourself the issues look related to the pg package? Have you tried to migrate back to the postgres package and see if that works?
what caused me to try the move to pg was the fact that it was happening with the postgres package.
Also stated is that reverting the upgrade to sveltekit2, even with the pg package, deploys to vercel successfully, as linked in the issue.
Went to make a more refined down example repo, and ran into something different but possibly still connected, documenting here.
- Since this is a build-time issue, using the stackblitz or whatever it's called ends up hanging after calling
npm run build. Like it says it transforms some modules, but hangs the terminal after that, no idea why as nothing ever gets displayed. - Because of (1) I decided to make a quick repo to test it out locally. Same setup i had:
drizzle-orm,pg, and some generic queries to a postgres db to make thenpm run devcommand happy, and to actually use the db client in case that provided me a false positive. Installed@sveltejs/adapter-vercel, set it up on thesvelte.config.jsand rannpm run buildand it worked perfectly - (2) was confusing, so i deleted the node modules and instead installed using
pnpm(which is what i normally use) and ranpnpm build. This failed with the following errors:
> Using @sveltejs/adapter-vercel
Warning: The following modules failed to locate dependencies that may (or may not) be required for your app to work:
node_modules\.pnpm\[email protected]\node_modules\pg\lib\native\client.js
- pg-native
error during build:
Error: EPERM: operation not permitted, symlink '.pnpm\[email protected]\node_modules\pg' -> 'C:\Users\Jim\projects\vercel-adapter-breaking\.vercel\output\functions\fn.func\node_modules\pg'
at Object.symlinkSync (node:fs:1801:11)
at create_function_bundle (file:///C:/Users/Jim/projects/vercel-adapter-breaking/node_modules/.pnpm/@[email protected]_@[email protected]/node_modules/@sveltejs/adapter-vercel/index.js:524:7)
at async generate_serverless_function (file:///C:/Users/Jim/projects/vercel-adapter-breaking/node_modules/.pnpm/@[email protected]_@[email protected]/node_modules/@sveltejs/adapter-vercel/index.js:80:5)
at async adapt (file:///C:/Users/Jim/projects/vercel-adapter-breaking/node_modules/.pnpm/@[email protected]_@[email protected]/node_modules/@sveltejs/adapter-vercel/index.js:246:5)
at async adapt (file:///C:/Users/Jim/projects/vercel-adapter-breaking/node_modules/.pnpm/@[email protected]_@[email protected][email protected][email protected]/node_modules/@sveltejs/kit/src/core/adapt/index.js:37:2)
at async finalise (file:///C:/Users/Jim/projects/vercel-adapter-breaking/node_modules/.pnpm/@[email protected]_@[email protected][email protected][email protected]/node_modules/@sveltejs/kit/src/exports/vite/index.js:825:7)
at async Object.handler (file:///C:/Users/Jim/projects/vercel-adapter-breaking/node_modules/.pnpm/@[email protected]_@[email protected][email protected][email protected]/node_modules/@sveltejs/kit/src/exports/vite/index.js:855:5)
at async PluginDriver.hookParallel (file:///C:/Users/Jim/projects/vercel-adapter-breaking/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.js:18561:17)
at async Object.close (file:///C:/Users/Jim/projects/vercel-adapter-breaking/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.js:19491:13)
at async build (file:///C:/Users/Jim/projects/vercel-adapter-breaking/node_modules/.pnpm/[email protected]/node_modules/vite/dist/node/chunks/dep-R0I0XnyH.js:66825:13)
ELIFECYCLE Command failed with exit code 1.
- So being a man of science I decided to try removing my current node modules in the project I see the original errors in and install using npm. Tried running both the version
^3.0.0of the@sveltejs/adapter-verceland4.0.3, both fail with the same errors.
Were you able to resolve this? I'm running into a similar issue with some of the same packages in a SvelteKit app for a crypto application. Wanting to use Vercel, but running into build failures. My project actually begins the build process and gets far along until it hits @sveltejs/adapter-vercel then it fails. I'm going to open a separate Issue.
@solanacryptodev i was not. Are you also using pnpm?
Please provide a minimal reproduction in the form of a code repository.
@eltigerchino For the second set of logs, https://github.com/jhechtf/vercel-adapter-breaking only breaks when using Pnpm. However, this is not the original set of errors I posted in regards to seeing the issue.