S
SolidJS2mo ago
gsoutz

__vite-browser-external:node:async_hooks:3 Uncaught Error: Module "node:async_hooks" has been extern

vite-browser-external:node:async_hooks:3 Uncaught Error: Module "node:async_hooks" has been externalized for browser compatibility. Cannot access "node:async_hooks.AsyncLocalStorage" in client code. See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details. at Object.get (vite-browser-external:node:async_hooks:3:11) at http.js:71:53 Here's my code looks like:
export const getUser = async (): Promise<User> => {
"use server"

const session = await getSession()

const user_id = session.data.user_id
let user: User | undefined
if (user_id) {
user = await user_by_id(user_id)
}

if (user) {
return user
}

user = create_user()

await new_user(user)
await session.update((d: UserSession) => ({ user_id: user.user_id }))
return user
}


export default function App() {

return (
<Router
root={props => (
<MetaProvider>
<Title>SolidStart - Basic</Title>
<Nav/>
<Suspense>{props.children}</Suspense>
</MetaProvider>
)}
>
<FileRoutes />
</Router>
);
}

const Nav = () => {
const user = createAsync(() => getUser(), { deferStream: true })

return (<>
<nav>
<a class='logo' href="/">duckchess<span>.org</span></a>
<Suspense>
<Show when={user()}>{user =>
<A class='dasher' href={`/u/${user().username}`}>{user().username}</A>
}</Show>
</Suspense>
</nav>
</>)
}
export const getUser = async (): Promise<User> => {
"use server"

const session = await getSession()

const user_id = session.data.user_id
let user: User | undefined
if (user_id) {
user = await user_by_id(user_id)
}

if (user) {
return user
}

user = create_user()

await new_user(user)
await session.update((d: UserSession) => ({ user_id: user.user_id }))
return user
}


export default function App() {

return (
<Router
root={props => (
<MetaProvider>
<Title>SolidStart - Basic</Title>
<Nav/>
<Suspense>{props.children}</Suspense>
</MetaProvider>
)}
>
<FileRoutes />
</Router>
);
}

const Nav = () => {
const user = createAsync(() => getUser(), { deferStream: true })

return (<>
<nav>
<a class='logo' href="/">duckchess<span>.org</span></a>
<Suspense>
<Show when={user()}>{user =>
<A class='dasher' href={`/u/${user().username}`}>{user().username}</A>
}</Show>
</Suspense>
</nav>
</>)
}
vitejs
Troubleshooting
Next Generation Frontend Tooling
1 Reply
gsoutz
gsoutzOP2mo ago
I think I solved it by putting "use server" inside getSession I didn't know every nested function call has to have that even though outer functions have it already.
Want results from more Discord servers?
Add your server