T
TanStack2mo ago
like-gold

Auth throwing errors

I just created fresh project with npm create @tanstack/start@latest -o tanstack-start-auth-test. Then added auth accordingly to Authentication. Ended up with a project that i zipped and attached here. When trying to run npm run build i get
error during build:
[vite]: Rollup failed to resolve import "tanstack-start-injected-head-scripts:v" from "C:/Users/MT/source/testprojects/tanstack-start-auth-test/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 ....
error during build:
[vite]: Rollup failed to resolve import "tanstack-start-injected-head-scripts:v" from "C:/Users/MT/source/testprojects/tanstack-start-auth-test/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 ....
4 Replies
like-gold
like-gold2mo ago
in this case, in src/authFunctions.ts exports both server functions (created via createServerFn) as well as export const useAppSession =... which made use of a server only functionality coming from @tanstack/react-start/server since that function was exported, it cannot be removed when compiling the server functions. removing export from that function makes it work we will make this better discoverable soon during dev and prod build
like-gold
like-goldOP2mo ago
useSession is server only? or isomorphic?
like-gold
like-gold2mo ago
server only needs access to headers / cookies
like-gold
like-goldOP2mo ago
oh ok, so it was kind of exposed with server function (endpoints) as i understand it and btw, docs need updating on auth , they suggest usage session.get('userId'). now it is strongly typed with session.data.userId and loginFn from the example gave me the following error on the "throw redirect"
There are few workarounds for this problem:
- Transform the value in a way that it can be serialized.
- If the reference is present on multiple runtimes (isomorphic), you can use the Reference API to map the references.
at CrossStreamParserContext.parseObject (file:///C:/Users/MT/source/repos/react-samples/tanstack-start/node_modules/seroval/dist/esm/development/index.mjs:3169:11)
at CrossStreamParserContext.parse (file:///C:/Users/MT/source/repos/react-samples/tanstack-start/node_modules/seroval/dist/esm/development/index.mjs:3197:52)
at CrossStreamParserContext.parseProperties (file:///C:/Users/MT/source/repos/react-samples/tanstack-start/node_modules/seroval/dist/esm/development/index.mjs:3278:28)
at CrossStreamParserContext.parsePlainObject (file:///C:/Users/MT/source/repos/react-samples/tanstack-start/node_modules/seroval/dist/esm/development/index.mjs:3000:12)
at CrossStreamParserContext.parseObject (file:///C:/Users/MT/source/repos/react-samples/tanstack-start/node_modules/seroval/dist/esm/development/index.mjs:3095:21)
at CrossStreamParserContext.parse (file:///C:/Users/MT/source/repos/react-samples/tanstack-start/node_modules/seroval/dist/esm/development/index.mjs:3197:52)
at CrossStreamParserContext.parseWithError (file:///C:/Users/MT/source/repos/react-samples/tanstack-start/node_modules/seroval/dist/esm/development/index.mjs:3437:19)
at CrossStreamParserContext.start (file:///C:/Users/MT/source/repos/react-samples/tanstack-start/node_modules/seroval/dist/esm/development/index.mjs:3447:25)
at toCrossJSONStream (file:///C:/Users/MT/source/repos/react-samples/tanstack-start/node_modules/seroval/dist/esm/development/index.mjs:3578:7)
There are few workarounds for this problem:
- Transform the value in a way that it can be serialized.
- If the reference is present on multiple runtimes (isomorphic), you can use the Reference API to map the references.
at CrossStreamParserContext.parseObject (file:///C:/Users/MT/source/repos/react-samples/tanstack-start/node_modules/seroval/dist/esm/development/index.mjs:3169:11)
at CrossStreamParserContext.parse (file:///C:/Users/MT/source/repos/react-samples/tanstack-start/node_modules/seroval/dist/esm/development/index.mjs:3197:52)
at CrossStreamParserContext.parseProperties (file:///C:/Users/MT/source/repos/react-samples/tanstack-start/node_modules/seroval/dist/esm/development/index.mjs:3278:28)
at CrossStreamParserContext.parsePlainObject (file:///C:/Users/MT/source/repos/react-samples/tanstack-start/node_modules/seroval/dist/esm/development/index.mjs:3000:12)
at CrossStreamParserContext.parseObject (file:///C:/Users/MT/source/repos/react-samples/tanstack-start/node_modules/seroval/dist/esm/development/index.mjs:3095:21)
at CrossStreamParserContext.parse (file:///C:/Users/MT/source/repos/react-samples/tanstack-start/node_modules/seroval/dist/esm/development/index.mjs:3197:52)
at CrossStreamParserContext.parseWithError (file:///C:/Users/MT/source/repos/react-samples/tanstack-start/node_modules/seroval/dist/esm/development/index.mjs:3437:19)
at CrossStreamParserContext.start (file:///C:/Users/MT/source/repos/react-samples/tanstack-start/node_modules/seroval/dist/esm/development/index.mjs:3447:25)
at toCrossJSONStream (file:///C:/Users/MT/source/repos/react-samples/tanstack-start/node_modules/seroval/dist/esm/development/index.mjs:3578:7)
at C:/Users/MT/source/repos/react-samples/tanstack-start/node_modules/@tanstack/start-server-core/dist/esm/server-functions-handler.js:207:9 {
value: Response {
status: 307,
statusText: '',
headers: Headers {},
body: null,
bodyUsed: false,
ok: false,
redirected: false,
type: 'default',
url: ''
}
}
Server Fn Error!
at C:/Users/MT/source/repos/react-samples/tanstack-start/node_modules/@tanstack/start-server-core/dist/esm/server-functions-handler.js:207:9 {
value: Response {
status: 307,
statusText: '',
headers: Headers {},
body: null,
bodyUsed: false,
ok: false,
redirected: false,
type: 'default',
url: ''
}
}
Server Fn Error!

Did you find this page helpful?