Error importing $env/static/private in hooks.server/index.ts in dev mode
Describe the bug
Importing from $env/static/private inside a file within a src/hooks.server/ folder results in an incorrect error in dev mode:
Internal server error: Cannot import $env/static/private into client-side code
At that point, the page has already been SSR rendered. No client-side code is attempting to import the env value.
The app builds and runs fine. And if src/hooks.server.ts is used, it works correctly in dev mode too. But using src/hooks.server/index.ts (which you may do if you have multiple hooks for instance) triggers the error.
It also seems like other server-only packages are imported into the client-side code if they are imported from the same file structure, but I need to experiment to reproduce exactly when it does / doesn't happen.
Reproduction
Skeleton project, with node adapter, and src/hooks.server/index.ts that imports something:
import { REDIS_URL } from '$env/static/private'
console.log('+hooks.server.ts', REDIS_URL)
export async function handle({ event, resolve }) {
return await resolve(event)
}
Logs
No response
System Info
System:
OS: macOS 14.3
CPU: (6) x64 Intel(R) Core(TM) i5-8500B CPU @ 3.00GHz
Memory: 1.36 GB / 32.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 20.6.1 - ~/Library/pnpm/node
npm: 9.8.1 - ~/Library/pnpm/npm
pnpm: 8.15.0 - ~/Library/pnpm/pnpm
bun: 1.0.0 - ~/.bun/bin/bun
Browsers:
Brave Browser: 106.1.44.112
Chrome: 120.0.6099.234
Chrome Canary: 123.0.6268.0
Safari: 17.3
Safari Technology Preview: 17.4
npmPackages:
@sveltejs/adapter-node: ^4.0.1 => 4.0.1
@sveltejs/kit: ^2.0.0 => 2.5.0
@sveltejs/vite-plugin-svelte: ^3.0.0 => 3.0.2
svelte: ^4.2.7 => 4.2.9
vite: ^5.0.3 => 5.0.12
Severity
blocking an upgrade
Additional Information
No response
Possibly related ... importing some server-only package from src/hooks.server.ts builds and runs fine:
import { Datastore } from '@google-cloud/datastore'
export const datastore = new Datastore()
export async function handle({ event, resolve }) {
return await resolve(event)
}
vite v5.0.12 building SSR bundle for production...
✓ 93 modules transformed.
+page.server.ts redis://localhost:6379
vite v5.0.12 building for production...
✓ 61 modules transformed.
.svelte-kit/output/client/_app/version.json 0.03 kB │ gzip: 0.05 kB
.svelte-kit/output/client/.vite/manifest.json 2.26 kB │ gzip: 0.46 kB
.svelte-kit/output/client/_app/immutable/entry/start.iL-ENaCG.js 0.07 kB │ gzip: 0.08 kB
.svelte-kit/output/client/_app/immutable/nodes/0.AMR_qFEh.js 0.60 kB │ gzip: 0.39 kB
.svelte-kit/output/client/_app/immutable/nodes/2.CBTThXjw.js 0.69 kB │ gzip: 0.45 kB
.svelte-kit/output/client/_app/immutable/nodes/1.eaFT8GcL.js 1.02 kB │ gzip: 0.59 kB
.svelte-kit/output/client/_app/immutable/chunks/scheduler.zMJaRgub.js 2.16 kB │ gzip: 1.02 kB
.svelte-kit/output/client/_app/immutable/chunks/index.jHcpu0S4.js 5.44 kB │ gzip: 2.31 kB
.svelte-kit/output/client/_app/immutable/entry/app.TkvBMoR8.js 5.96 kB │ gzip: 2.41 kB
.svelte-kit/output/client/_app/immutable/chunks/entry.zd_AHcGl.js 26.89 kB │ gzip: 10.65 kB
✓ built in 406ms
.svelte-kit/output/server/.vite/manifest.json 2.32 kB
.svelte-kit/output/server/entries/pages/_page.server.ts.js 0.15 kB
.svelte-kit/output/server/chunks/hooks.server.js 0.20 kB
.svelte-kit/output/server/entries/fallbacks/layout.svelte.js 0.24 kB
.svelte-kit/output/server/internal.js 0.31 kB
.svelte-kit/output/server/entries/pages/_page.svelte.js 0.37 kB
.svelte-kit/output/server/entries/fallbacks/error.svelte.js 1.16 kB
.svelte-kit/output/server/chunks/ssr.js 3.35 kB
.svelte-kit/output/server/chunks/exports.js 5.96 kB
.svelte-kit/output/server/chunks/internal.js 6.07 kB
.svelte-kit/output/server/index.js 115.00 kB
Run npm run preview to preview your production build locally.
> Using @sveltejs/adapter-node
✔ done
✓ built in 2.30s
But if the same import is in src/hooks.server/index.ts instead, it tries to add everything to the client-side code:
vite v5.0.12 building SSR bundle for production...
✓ 93 modules transformed.
+page.server.ts redis://localhost:6379
vite v5.0.12 building for production...
[plugin:vite:resolve] Module "stream" has been externalized for browser compatibility, imported by "/Users/simon/dev/temp/sk-env-static-private/node_modules/.pnpm/@[email protected]/node_modules/@google-cloud/datastore/build/src/index.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] Module "path" has been externalized for browser compatibility, imported by "/Users/simon/dev/temp/sk-env-static-private/node_modules/.pnpm/@[email protected]/node_modules/@google-cloud/datastore/build/src/entity.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] Module "stream" has been externalized for browser compatibility, imported by "/Users/simon/dev/temp/sk-env-static-private/node_modules/.pnpm/@[email protected]/node_modules/@google-cloud/datastore/build/src/request.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] Module "querystring" has been externalized for browser compatibility, imported by "/Users/simon/dev/temp/sk-env-static-private/node_modules/.pnpm/[email protected]/node_modules/google-gax/build/src/routingHeader.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] Module "stream" has been externalized for browser compatibility, imported by "/Users/simon/dev/temp/sk-env-static-private/node_modules/.pnpm/[email protected]/node_modules/google-gax/build/src/fallbackServiceStub.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] Module "events" has been externalized for browser compatibility, imported by "/Users/simon/dev/temp/sk-env-static-private/node_modules/.pnpm/[email protected]/node_modules/google-gax/build/src/longRunningCalls/longrunning.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] Module "events" has been externalized for browser compatibility, imported by "/Users/simon/dev/temp/sk-env-static-private/node_modules/.pnpm/[email protected]/node_modules/google-auth-library/build/src/auth/authclient.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] Module "querystring" has been externalized for browser compatibility, imported by "/Users/simon/dev/temp/sk-env-static-private/node_modules/.pnpm/[email protected]/node_modules/google-auth-library/build/src/auth/oauth2client.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] Module "stream" has been externalized for browser compatibility, imported by "/Users/simon/dev/temp/sk-env-static-private/node_modules/.pnpm/[email protected]/node_modules/google-auth-library/build/src/auth/oauth2client.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] Module "fs" has been externalized for browser compatibility, imported by "/Users/simon/dev/temp/sk-env-static-private/node_modules/.pnpm/[email protected]/node_modules/google-auth-library/build/src/auth/identitypoolclient.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] Module "util" has been externalized for browser compatibility, imported by "/Users/simon/dev/temp/sk-env-static-private/node_modules/.pnpm/[email protected]/node_modules/google-auth-library/build/src/auth/identitypoolclient.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] Module "stream" has been externalized for browser compatibility, imported by "/Users/simon/dev/temp/sk-env-static-private/node_modules/.pnpm/[email protected]/node_modules/google-auth-library/build/src/auth/downscopedclient.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] Module "stream" has been externalized for browser compatibility, imported by "/Users/simon/dev/temp/sk-env-static-private/node_modules/.pnpm/[email protected]/node_modules/google-auth-library/build/src/auth/baseexternalclient.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] Module "stream" has been externalized for browser compatibility, imported by "/Users/simon/dev/temp/sk-env-static-private/node_modules/.pnpm/[email protected]/node_modules/google-gax/build/src/streamArrayParser.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] Module "stream" has been externalized for browser compatibility, imported by "/Users/simon/dev/temp/sk-env-static-private/node_modules/.pnpm/[email protected]/node_modules/google-gax/build/src/streamingRetryRequest.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] Module "stream" has been externalized for browser compatibility, imported by "/Users/simon/dev/temp/sk-env-static-private/node_modules/.pnpm/[email protected]/node_modules/google-gax/build/src/paginationCalls/pageDescriptor.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] Module "child_process" has been externalized for browser compatibility, imported by "/Users/simon/dev/temp/sk-env-static-private/node_modules/.pnpm/[email protected]/node_modules/google-auth-library/build/src/auth/googleauth.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] Module "fs" has been externalized for browser compatibility, imported by "/Users/simon/dev/temp/sk-env-static-private/node_modules/.pnpm/[email protected]/node_modules/google-auth-library/build/src/auth/googleauth.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] Module "os" has been externalized for browser compatibility, imported by "/Users/simon/dev/temp/sk-env-static-private/node_modules/.pnpm/[email protected]/node_modules/google-auth-library/build/src/auth/googleauth.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] Module "path" has been externalized for browser compatibility, imported by "/Users/simon/dev/temp/sk-env-static-private/node_modules/.pnpm/[email protected]/node_modules/google-auth-library/build/src/auth/googleauth.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] Module "fs" has been externalized for browser compatibility, imported by "/Users/simon/dev/temp/sk-env-static-private/node_modules/.pnpm/[email protected]/node_modules/gtoken/build/src/index.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] Module "path" has been externalized for browser compatibility, imported by "/Users/simon/dev/temp/sk-env-static-private/node_modules/.pnpm/[email protected]/node_modules/gtoken/build/src/index.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] Module "util" has been externalized for browser compatibility, imported by "/Users/simon/dev/temp/sk-env-static-private/node_modules/.pnpm/[email protected]/node_modules/gtoken/build/src/index.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] Module "querystring" has been externalized for browser compatibility, imported by "/Users/simon/dev/temp/sk-env-static-private/node_modules/.pnpm/[email protected]/node_modules/google-auth-library/build/src/auth/stscredentials.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] Module "stream" has been externalized for browser compatibility, imported by "/Users/simon/dev/temp/sk-env-static-private/node_modules/.pnpm/[email protected]/node_modules/retry-request/index.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] Module "events" has been externalized for browser compatibility, imported by "/Users/simon/dev/temp/sk-env-static-private/node_modules/.pnpm/[email protected]/node_modules/readable-stream/lib/_stream_readable.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] Module "buffer" has been externalized for browser compatibility, imported by "/Users/simon/dev/temp/sk-env-static-private/node_modules/.pnpm/[email protected]/node_modules/readable-stream/lib/_stream_readable.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] Module "buffer" has been externalized for browser compatibility, imported by "/Users/simon/dev/temp/sk-env-static-private/node_modules/.pnpm/[email protected]/node_modules/readable-stream/lib/_stream_writable.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] Module "fs" has been externalized for browser compatibility, imported by "/Users/simon/dev/temp/sk-env-static-private/node_modules/.pnpm/[email protected]/node_modules/gcp-metadata/build/src/gcp-residency.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] Module "os" has been externalized for browser compatibility, imported by "/Users/simon/dev/temp/sk-env-static-private/node_modules/.pnpm/[email protected]/node_modules/gcp-metadata/build/src/gcp-residency.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] Module "stream" has been externalized for browser compatibility, imported by "/Users/simon/dev/temp/sk-env-static-private/node_modules/.pnpm/[email protected]/node_modules/google-auth-library/build/src/auth/externalAccountAuthorizedUserClient.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] Module "url" has been externalized for browser compatibility, imported by "/Users/simon/dev/temp/sk-env-static-private/node_modules/.pnpm/[email protected]/node_modules/gaxios/build/src/common.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] Module "stream" has been externalized for browser compatibility, imported by "/Users/simon/dev/temp/sk-env-static-private/node_modules/.pnpm/[email protected]/node_modules/jws/lib/sign-stream.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] Module "util" has been externalized for browser compatibility, imported by "/Users/simon/dev/temp/sk-env-static-private/node_modules/.pnpm/[email protected]/node_modules/jws/lib/sign-stream.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] Module "stream" has been externalized for browser compatibility, imported by "/Users/simon/dev/temp/sk-env-static-private/node_modules/.pnpm/[email protected]/node_modules/jws/lib/verify-stream.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] Module "util" has been externalized for browser compatibility, imported by "/Users/simon/dev/temp/sk-env-static-private/node_modules/.pnpm/[email protected]/node_modules/jws/lib/verify-stream.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] Module "buffer" has been externalized for browser compatibility, imported by "/Users/simon/dev/temp/sk-env-static-private/node_modules/.pnpm/[email protected]/node_modules/safe-buffer/index.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] Module "crypto" has been externalized for browser compatibility, imported by "/Users/simon/dev/temp/sk-env-static-private/node_modules/.pnpm/[email protected]/node_modules/google-auth-library/build/src/crypto/node/crypto.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] Module "querystring" has been externalized for browser compatibility, imported by "/Users/simon/dev/temp/sk-env-static-private/node_modules/.pnpm/[email protected]/node_modules/google-auth-library/build/src/auth/oauth2common.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] Module "https" has been externalized for browser compatibility, imported by "/Users/simon/dev/temp/sk-env-static-private/node_modules/.pnpm/[email protected]/node_modules/gaxios/build/src/gaxios.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] Module "querystring" has been externalized for browser compatibility, imported by "/Users/simon/dev/temp/sk-env-static-private/node_modules/.pnpm/[email protected]/node_modules/gaxios/build/src/gaxios.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] Module "url" has been externalized for browser compatibility, imported by "/Users/simon/dev/temp/sk-env-static-private/node_modules/.pnpm/[email protected]/node_modules/gaxios/build/src/gaxios.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] Module "child_process" has been externalized for browser compatibility, imported by "/Users/simon/dev/temp/sk-env-static-private/node_modules/.pnpm/[email protected]/node_modules/google-auth-library/build/src/auth/pluggable-auth-handler.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] Module "fs" has been externalized for browser compatibility, imported by "/Users/simon/dev/temp/sk-env-static-private/node_modules/.pnpm/[email protected]/node_modules/google-auth-library/build/src/auth/pluggable-auth-handler.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] Module "events" has been externalized for browser compatibility, imported by "/Users/simon/dev/temp/sk-env-static-private/node_modules/.pnpm/[email protected]/node_modules/readable-stream/lib/internal/streams/stream-browser.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] Module "buffer" has been externalized for browser compatibility, imported by "/Users/simon/dev/temp/sk-env-static-private/node_modules/.pnpm/[email protected]/node_modules/readable-stream/lib/internal/streams/buffer_list.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] Module "stream" has been externalized for browser compatibility, imported by "/Users/simon/dev/temp/sk-env-static-private/node_modules/.pnpm/[email protected]/node_modules/jws/lib/data-stream.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] Module "util" has been externalized for browser compatibility, imported by "/Users/simon/dev/temp/sk-env-static-private/node_modules/.pnpm/[email protected]/node_modules/jws/lib/data-stream.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] Module "crypto" has been externalized for browser compatibility, imported by "/Users/simon/dev/temp/sk-env-static-private/node_modules/.pnpm/[email protected]/node_modules/jwa/index.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] Module "util" has been externalized for browser compatibility, imported by "/Users/simon/dev/temp/sk-env-static-private/node_modules/.pnpm/[email protected]/node_modules/jwa/index.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] Module "buffer" has been externalized for browser compatibility, imported by "/Users/simon/dev/temp/sk-env-static-private/node_modules/.pnpm/[email protected]/node_modules/jws/lib/tostring.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] Module "net" has been externalized for browser compatibility, imported by "/Users/simon/dev/temp/sk-env-static-private/node_modules/.pnpm/[email protected]/node_modules/https-proxy-agent/dist/index.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] Module "tls" has been externalized for browser compatibility, imported by "/Users/simon/dev/temp/sk-env-static-private/node_modules/.pnpm/[email protected]/node_modules/https-proxy-agent/dist/index.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] Module "assert" has been externalized for browser compatibility, imported by "/Users/simon/dev/temp/sk-env-static-private/node_modules/.pnpm/[email protected]/node_modules/https-proxy-agent/dist/index.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] Module "buffer" has been externalized for browser compatibility, imported by "/Users/simon/dev/temp/sk-env-static-private/node_modules/.pnpm/[email protected]/node_modules/buffer-equal-constant-time/index.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] Module "http" has been externalized for browser compatibility, imported by "/Users/simon/dev/temp/sk-env-static-private/node_modules/.pnpm/[email protected]/node_modules/agent-base/dist/index.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] Module "http" has been externalized for browser compatibility, imported by "/Users/simon/dev/temp/sk-env-static-private/node_modules/.pnpm/[email protected]/node_modules/agent-base/dist/helpers.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] Module "https" has been externalized for browser compatibility, imported by "/Users/simon/dev/temp/sk-env-static-private/node_modules/.pnpm/[email protected]/node_modules/agent-base/dist/helpers.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
node_modules/.pnpm/@[email protected]/node_modules/@protobufjs/inquire/index.js (12:18) Use of eval in "node_modules/.pnpm/@[email protected]/node_modules/@protobufjs/inquire/index.js" is strongly discouraged as it poses security risks and may cause issues with minification.
.svelte-kit/generated/client-optimized/app.js (20:26) "reroute" is not exported by "src/hooks.server/index.ts", imported by ".svelte-kit/generated/client-optimized/app.js".
✓ 614 modules transformed.
.svelte-kit/output/client/_app/version.json 0.03 kB │ gzip: 0.05 kB
.svelte-kit/output/client/.vite/manifest.json 2.26 kB │ gzip: 0.46 kB
.svelte-kit/output/client/_app/immutable/entry/start.M7gfaKSI.js 0.07 kB │ gzip: 0.08 kB
.svelte-kit/output/client/_app/immutable/nodes/0.o0VDc14w.js 0.60 kB │ gzip: 0.39 kB
.svelte-kit/output/client/_app/immutable/nodes/2.8kBH4q3p.js 0.69 kB │ gzip: 0.45 kB
.svelte-kit/output/client/_app/immutable/nodes/1.EALVzDft.js 1.02 kB │ gzip: 0.60 kB
.svelte-kit/output/client/_app/immutable/chunks/scheduler.yJWdLb0b.js 2.16 kB │ gzip: 1.02 kB
.svelte-kit/output/client/_app/immutable/chunks/index.a_7mwJ74.js 5.44 kB │ gzip: 2.31 kB
.svelte-kit/output/client/_app/immutable/chunks/entry._Uoe0qpq.js 26.88 kB │ gzip: 10.65 kB
.svelte-kit/output/client/_app/immutable/entry/app.Vd6jm0Kj.js 1,094.76 kB │ gzip: 229.43 kB
(!) Some chunks are larger than 500 kB after minification. Consider:
- Using dynamic import() to code-split the application
- Use build.rollupOptions.output.manualChunks to improve chunking: https://rollupjs.org/configuration-options/#output-manualchunks
- Adjust chunk size limit for this warning via build.chunkSizeWarningLimit.
✓ built in 3.56s
.svelte-kit/output/server/.vite/manifest.json 2.37 kB
.svelte-kit/output/server/entries/pages/_page.server.ts.js 0.15 kB
.svelte-kit/output/server/chunks/index.js 0.20 kB
.svelte-kit/output/server/entries/fallbacks/layout.svelte.js 0.24 kB
.svelte-kit/output/server/internal.js 0.31 kB
.svelte-kit/output/server/entries/pages/_page.svelte.js 0.37 kB
.svelte-kit/output/server/entries/fallbacks/error.svelte.js 1.16 kB
.svelte-kit/output/server/chunks/ssr.js 3.35 kB
.svelte-kit/output/server/chunks/exports.js 5.96 kB
.svelte-kit/output/server/chunks/internal.js 6.10 kB
.svelte-kit/output/server/index.js 115.00 kB
Run npm run preview to preview your production build locally.
> Using @sveltejs/adapter-node
✔ done
✓ built in 5.58s
Summary: using $env, or trying to use modules in any way to arrange hooks (e.g. using sequence) results in these dev or build errors.
The only thing that works is to put everything into one giant src/hooks.server.ts file, which is fugly, but a workaround for anyone else facing these issues.
Still getting this, but discovered if I add an empty src/hooks.client/index.ts it fixes the error and allows me to keep the src/hooks.server folder
The issue is that the search for shared "hooks" finds and matches the "hooks.server" folder, which is then imported into the client-side code, causing errors.
Reproduction here: https://www.sveltelab.dev/egkmtnbmy05petz
I think the match needs to just cut off the .js or .ts part of a filename, not the potential .server or .client
NOTE: this doesn't seem to be 100% consistent - I'm guessing it's whatever order the file system returns things in, that may change, but would explain why this issue has come and gone on several projects I've worked on. Sometimes it randomly appears, then can just as randomly seem to fix itself.