T
TanStack2mo ago
extended-salmon

[Build] tanstack-start-injected-head-scriptRollup failed to resolve import "tanstack-start-injected-

Trying to build my project. Getting;
✓ 3364 modules transformed.
✗ Build failed in 1.72s
error during build:
[vite]: Rollup failed to resolve import "tanstack-start-injected-head-scripts:v" from "/Users/franciszekstodulski/Dev/@others/wizytka/node_modules/@tanstack/start-server-core/dist/esm/loadVirtualModule.js".
This is most likely unintended because it can break your application at runtime.
If you do want to externalize this module explicitly add it to
`build.rollupOptions.external`
at viteLog (file:///Users/franciszekstodulski/Dev/@others/wizytka/node_modules/vite/dist/node/chunks/dep-B0GuR2De.js:33864:57)
.........
✓ 3364 modules transformed.
✗ Build failed in 1.72s
error during build:
[vite]: Rollup failed to resolve import "tanstack-start-injected-head-scripts:v" from "/Users/franciszekstodulski/Dev/@others/wizytka/node_modules/@tanstack/start-server-core/dist/esm/loadVirtualModule.js".
This is most likely unintended because it can break your application at runtime.
If you do want to externalize this module explicitly add it to
`build.rollupOptions.external`
at viteLog (file:///Users/franciszekstodulski/Dev/@others/wizytka/node_modules/vite/dist/node/chunks/dep-B0GuR2De.js:33864:57)
.........
No idea what cause that.. Using orpc, using getRequestHeaders in my server functions.. no idea.
26 Replies
jolly-crimson
jolly-crimson2mo ago
Same issue, how did you fix it?
genetic-orange
genetic-orange2mo ago
if you're importing getRequestHeaders from @tanstack/start-server-core, just don't that's how i fixed it at least
extended-salmon
extended-salmonOP2mo ago
That was my idea too. But my app was too big. Just switched to next. I will use tan stack when it’s more stable
jolly-crimson
jolly-crimson2mo ago
I am not importing getRequestHeaders anywhere in my app, what can be the issue?
adverse-sapphire
adverse-sapphire2mo ago
I know this issue happens if you try to call "getRequestHeaders()" in a beforeLoad for example i assume it can happen with any function in @tanstack/react-start/server and i think it's logic cause those functions should be called only in server functions ? that's the issue ? look at any place you use a function from @tanstack/react-start/server @fstodulski
extended-salmon
extended-salmonOP2mo ago
Already migrated back to nextjs
adverse-sapphire
adverse-sapphire2mo ago
noooooo
extended-salmon
extended-salmonOP2mo ago
I spend 3 days on it. No idea where the issue was. I got different build issues - even on clean fresh projects - from TStack and Better Stack - even examples… will be back on it when it’s ready - is super dope project - definitely will use it someday
optimistic-gold
optimistic-gold2mo ago
please provide a full project
optimistic-gold
optimistic-gold2mo ago
could you be more specific on this wrong use please? i'm getting this error in my project after migrating from next.js. and i'm using getRequestHeaders() but not using any beforeLoad in my repo. i'm not sure what's wrong
optimistic-gold
optimistic-gold2mo ago
No description
adverse-sapphire
adverse-sapphire2mo ago
in which place you use it ?
optimistic-gold
optimistic-gold2mo ago
i'm using it in two places: 1.
// get-user-settings.ts
export function getUserSettings() {
// here i'm using better-auth which requires a header
const session = await auth.api.getSession({ headers: getRequestHeaders() });
// ...
}
// get-user-settings.ts
export function getUserSettings() {
// here i'm using better-auth which requires a header
const session = await auth.api.getSession({ headers: getRequestHeaders() });
// ...
}
then in my route file, i import this function and consume in the loader 2. i followed the orpc guide on set up the client https://orpc.unnoq.com/docs/adapters/tanstack-start#optimize-ssr
adverse-sapphire
adverse-sapphire2mo ago
yep thats's the issue, you should use a "getRequestHeaders()" ONLY in server functions so via "createServerFn" or via "createIsomorphicFn"
No description
adverse-sapphire
adverse-sapphire2mo ago
that's how i do it and then i use this function with tanstack query
optimistic-gold
optimistic-gold2mo ago
ah i see. so my first usage is causing issue. i should refer to the orpc doc's createIsomorphicFn usage thanks! i'll try change that
rival-black
rival-black2mo ago
optimistic-gold
optimistic-gold2mo ago
sadly i'm still seeing this issue. for my point 1). i've replace all my getUserFn to what looks like in your screenshot. 🙁 i wish the error prompt could be better
No description
adverse-sapphire
adverse-sapphire2mo ago
maybe you are still using any other function that comes from "@tanstack/react-start/server" in the wrong way oh wait, can you show your client.ts ?
optimistic-gold
optimistic-gold2mo ago
omg nice catch. i found i'm using:
import { getCookie } from "@tanstack/react-start/server";
import { getCookie } from "@tanstack/react-start/server";
as well. after changing it into createIsomorphicFn, now everything works! thank you so much!!!!
adverse-sapphire
adverse-sapphire2mo ago
nice !
optimistic-gold
optimistic-gold2mo ago
there are still some other issues though. but this error is gone! i'll continue the migration 😄 ❤️
rival-black
rival-black2mo ago
👋
extended-salmon
extended-salmonOP2mo ago
Hey @sirca How do you use it in your components?
adverse-sapphire
adverse-sapphire2mo ago
use what, the auth example i sent ?
frozen-sapphire
frozen-sapphire2w ago
Hi guys I am also getting this error, I have read this thread but I am not able to fix it. I use better auth, I have a Pathless Layout Component _app.tsx where I have a beforeLoad where I call 'authWithOrgStateFn' isomorphicFn which is something similar to @sirca its example, other then that I have some serverFn which I consume in my components using useServerFn with Tanstack Query. How can I trace the cause? Does someone have an idea?

Did you find this page helpful?