djbalin
djbalin•5mo ago

[Convex Auth]: Monorepo Expo app: "Unable to resolve @convex-dev/auth/server" ...

Hi, we're building a Turbo Monorepo Expo app and are running into the error pasted below when running the Expo dev server from our native package. The error occurs during bundling when we try to open our iOS app. Our native app in apps/native/package.json has a dependency on packages/backend as "@flimmer/backend": "*",
iOS Bundling failed 45379ms C:\Users\jgbal\Desktop\code\flimmer-monorepo\node_modules\expo-router\entry.js (1823 modules)
Unable to resolve "@convex-dev/auth/server" from "..\..\packages\backend\convex\schema.ts"
iOS Bundling failed 45379ms C:\Users\jgbal\Desktop\code\flimmer-monorepo\node_modules\expo-router\entry.js (1823 modules)
Unable to resolve "@convex-dev/auth/server" from "..\..\packages\backend\convex\schema.ts"
The iOS device error gives this information:
Unable to resolve module @convex-dev/auth/server from C:\Users\jgbal\Desktop\code\flimmer-monorepo\packages\backend\convex\schema.ts: @convex-dev/auth/server could not be found within the project or in these directories: node_modules, ..\..\node_modules
...
> 18 | import {authTables} from '@convex-dev/auth/server';
Unable to resolve module @convex-dev/auth/server from C:\Users\jgbal\Desktop\code\flimmer-monorepo\packages\backend\convex\schema.ts: @convex-dev/auth/server could not be found within the project or in these directories: node_modules, ..\..\node_modules
...
> 18 | import {authTables} from '@convex-dev/auth/server';
Thank you!
6 Replies
Michal Srb
Michal Srb•5mo ago
You probably need the rest of https://github.com/get-convex/convex-auth/pull/39/files I'll let you know when it's fixed
djbalin
djbalinOP•5mo ago
Thanks @Michal Srb. Any idea of when this fix might be rolled out? And is there any way we could temporarily implement this fix now, if we want to?
Michal Srb
Michal Srb•5mo ago
@djbalin try it now with 0.0.46
djbalin
djbalinOP•5mo ago
@Michal Srb Thank you very much for the swift action Michal! We are running into a different but similar issue now. The oslo package cannot be resolved from @convex-dev\auth\dist\server\implementation.js (see attached screenshot of CLI and grandfather screenshot of physical device). If you know of a temporary/ghetto fix that we can employ and leave you with some peace of mind to look into this further, please let me know 🙂
No description
No description
Michal Srb
Michal Srb•5mo ago
Hmm, then this might not be a viable path. I have an Expo app working with Convex Auth, so this must be specific to Turborepo + Expo. Will talk with @ballingt later on how to resolve this. One thing that might help you figure this out is that your mobile frontend should not need @convex-dev/auth/server. It should only depend on your backend for types. This is how the non-monorepo Expo setup works.
djbalin
djbalinOP•5mo ago
I think I found and resolved the issue! What you mentioned here was key: "your mobile frontend should not need @convex-dev/auth/server. It should only depend on your backend for types." Our file backend/convex/utils.ts contained this helper function (which was currently not being used anywhere actually):
import schema from './schema';
export const docValidator = <T extends TableNames>(
tableName: T
): Validator<Doc<T>, 'required', any> => {
const validator = schema.tables[tableName].validator;
if (validator.kind !== 'object') {
throw new Error(`Not an object validator`);
}
return v.object({
...validator.fields,
_id: v.id(tableName),
_creationTime: v.number(),
});
};
import schema from './schema';
export const docValidator = <T extends TableNames>(
tableName: T
): Validator<Doc<T>, 'required', any> => {
const validator = schema.tables[tableName].validator;
if (validator.kind !== 'object') {
throw new Error(`Not an object validator`);
}
return v.object({
...validator.fields,
_id: v.id(tableName),
_creationTime: v.number(),
});
};
However, our frontend/native app uses a yatesShuffle helper function also found within this same file. This means that, as far as my rough understanding goes, when the native app uses yatesShuffle, it must parse the entire utils.ts file which then imports schema from './schema.ts', somehow causing the node module resolution error. Simply commenting out the import schema business above seems to have done the trick! Now our native app doesn't try to parse the schema.ts file, and the error has disappeared. I'll update you here if we run into further issues, but otherwise thank you so much for the quick help @Michal Srb! 🌞