-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error importing $env/static/private in hooks.server/index.ts in dev mode #11754
Comments
Possibly related ... importing some server-only package from import { Datastore } from '@google-cloud/datastore'
export const datastore = new Datastore()
export async function handle({ event, resolve }) {
return await resolve(event)
}
But if the same import is in
|
Summary: using The only thing that works is to put everything into one giant |
Still getting this, but discovered if I add an empty |
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 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. |
Describe the bug
Importing from
$env/static/private
inside a file within asrc/hooks.server/
folder results in an incorrect error in dev mode: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 usingsrc/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:Logs
No response
System Info
Severity
blocking an upgrade
Additional Information
No response
The text was updated successfully, but these errors were encountered: