r9d7
r9d7
Explore posts from servers
DTDrizzle Team
Created by r9d7 on 9/23/2024 in #help
Error: Cannot access 'interactionsRelations' before initialization
Not the best solution for my project but I just finished refactoring so the app doesn't crash anymore...
11 replies
DTDrizzle Team
Created by r9d7 on 9/23/2024 in #help
Error: Cannot access 'interactionsRelations' before initialization
I tried running pnpm db:push with both export const and export let for every table & relation but those would always crash
11 replies
DTDrizzle Team
Created by r9d7 on 9/23/2024 in #help
Error: Cannot access 'interactionsRelations' before initialization
What ended up working for me was moving every table & relation definition to one schema.ts file, and making sure to export var everything
11 replies
DTDrizzle Team
Created by r9d7 on 9/23/2024 in #help
Error: Cannot access 'interactionsRelations' before initialization
This is the most likely cause but I tested my code with madge but it didn't find any circular dependency
11 replies
DTDrizzle Team
Created by r9d7 on 9/23/2024 in #help
Error: Cannot access 'interactionsRelations' before initialization
I tried that with no success 😦
11 replies
DTDrizzle Team
Created by r9d7 on 9/23/2024 in #help
Error: Cannot access 'interactionsRelations' before initialization
And this is the error I get when I run pnpm db:push:
> @ws0/[email protected] db:push /Users/.../monorepo/apps/web
> drizzle-kit push --config=src/config/db.ts

Reading config file '/Users/.../monorepo/apps/web/src/config/db.ts'
Using 'postgres' driver for database querying
[✓] Pulling schema from database...
ReferenceError: Cannot access 'interactionsRelations' before initialization
at Object.interactionsRelations (/Users/.../monorepo/apps/web/src/lib/api/interactions/interactions.relations.schema.ts:1:1)
at Object.get [as interactionsRelations] (/Users/.../monorepo/apps/web/src/lib/api/interactions/interactions.relations.schema.ts:14:45)
at Object.get [as interactionsRelations] (/Users/.../monorepo/apps/web/src/lib/db/relations.ts:10:45)
at Object.get [as interactionsRelations] (/Users/.../monorepo/apps/web/src/lib/db/index.ts:16:45)
at Object.<anonymous> (/Users/.../monorepo/apps/web/src/lib/db/index.ts:11:66)
at Module._compile (node:internal/modules/cjs/loader:1469:14)
at Module._compile (/Users/.../monorepo/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/bin.cjs:14679:30)
at Module._extensions..js (node:internal/modules/cjs/loader:1548:10)
at Object.newLoader [as .ts] (/Users/.../monorepo/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/bin.cjs:14683:13)
at Module.load (node:internal/modules/cjs/loader:1288:32)
> @ws0/[email protected] db:push /Users/.../monorepo/apps/web
> drizzle-kit push --config=src/config/db.ts

Reading config file '/Users/.../monorepo/apps/web/src/config/db.ts'
Using 'postgres' driver for database querying
[✓] Pulling schema from database...
ReferenceError: Cannot access 'interactionsRelations' before initialization
at Object.interactionsRelations (/Users/.../monorepo/apps/web/src/lib/api/interactions/interactions.relations.schema.ts:1:1)
at Object.get [as interactionsRelations] (/Users/.../monorepo/apps/web/src/lib/api/interactions/interactions.relations.schema.ts:14:45)
at Object.get [as interactionsRelations] (/Users/.../monorepo/apps/web/src/lib/db/relations.ts:10:45)
at Object.get [as interactionsRelations] (/Users/.../monorepo/apps/web/src/lib/db/index.ts:16:45)
at Object.<anonymous> (/Users/.../monorepo/apps/web/src/lib/db/index.ts:11:66)
at Module._compile (node:internal/modules/cjs/loader:1469:14)
at Module._compile (/Users/.../monorepo/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/bin.cjs:14679:30)
at Module._extensions..js (node:internal/modules/cjs/loader:1548:10)
at Object.newLoader [as .ts] (/Users/.../monorepo/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/bin.cjs:14683:13)
at Module.load (node:internal/modules/cjs/loader:1288:32)
11 replies
DTDrizzle Team
Created by r9d7 on 9/23/2024 in #help
Error: Cannot access 'interactionsRelations' before initialization
But I never import a .relation.schema file from a .schema file, only the other way around
11 replies
DTDrizzle Team
Created by r9d7 on 9/23/2024 in #help
Error: Cannot access 'interactionsRelations' before initialization
A .relation.schema file can reference .schema files like so:
import { relations } from "drizzle-orm";

import { creatorsToPosts, interactions, posts, users } from "~/lib/db/schema";

export const usersRelations = relations(users, ({ many }) => ({
creatorsToPosts: many(creatorsToPosts, { relationName: "creatorsToPosts" }),
interactions: many(interactions),
}));

export const creatorsToPostsRelations = relations(
creatorsToPosts,
({ one }) => ({
creator: one(users, {
fields: [creatorsToPosts.creatorId],
references: [users.id],
relationName: "creatorsToPosts",
}),
post: one(posts, {
fields: [creatorsToPosts.postPublicId],
references: [posts.publicId],
relationName: "postsToCreators",
}),
}),
);
import { relations } from "drizzle-orm";

import { creatorsToPosts, interactions, posts, users } from "~/lib/db/schema";

export const usersRelations = relations(users, ({ many }) => ({
creatorsToPosts: many(creatorsToPosts, { relationName: "creatorsToPosts" }),
interactions: many(interactions),
}));

export const creatorsToPostsRelations = relations(
creatorsToPosts,
({ one }) => ({
creator: one(users, {
fields: [creatorsToPosts.creatorId],
references: [users.id],
relationName: "creatorsToPosts",
}),
post: one(posts, {
fields: [creatorsToPosts.postPublicId],
references: [posts.publicId],
relationName: "postsToCreators",
}),
}),
);
11 replies
RRailway
Created by r9d7 on 3/19/2024 in #✋|help
Custom build script crashing
Well, I'm all happy now that it works so your input is very much appreciated
32 replies
RRailway
Created by r9d7 on 3/19/2024 in #✋|help
Custom build script crashing
And thank you for your time. Your suggestion about the monorepo setup is what fixed it I think
32 replies
RRailway
Created by r9d7 on 3/19/2024 in #✋|help
Custom build script crashing
Looks like its working now, sorry for the stupid mistakes
32 replies
RRailway
Created by r9d7 on 3/19/2024 in #✋|help
Custom build script crashing
Oops gimme 2 sec, just realised I had forgotten to push my changes after committing
32 replies
RRailway
Created by r9d7 on 3/19/2024 in #✋|help
Custom build script crashing
Failed again
32 replies
RRailway
Created by r9d7 on 3/19/2024 in #✋|help
Custom build script crashing
The prev build had the same scripts in the root package.json, the only difference was that the custom build & start commands were using npm run instead of pnpm
32 replies
RRailway
Created by r9d7 on 3/19/2024 in #✋|help
Custom build script crashing
No description
32 replies
RRailway
Created by r9d7 on 3/19/2024 in #✋|help
Custom build script crashing
Will try to run it with pnpm instead of npm run
32 replies
RRailway
Created by r9d7 on 3/19/2024 in #✋|help
Custom build script crashing
It is failing again 😦
32 replies
RRailway
Created by r9d7 on 3/19/2024 in #✋|help
Custom build script crashing
No description
32 replies
RRailway
Created by r9d7 on 3/19/2024 in #✋|help
Custom build script crashing
But I don't understand why that would be an issue now since I only have one app
32 replies