Module Resolution Issue After Restructuring Project
Unanswered
Axus posted this in #help-forum
AxusOP
Hi,
I’m encountering a MODULE_NOT_FOUND error when running a seed script in my project. The issue started after I restructured the project, even though the paths and configurations seem correct. Before the refactor, everything worked perfectly.
Context
I’m using ts-node to run a Prisma seed script:
The tsconfig.json is configured with:
src/
lib/
actionFlower.ts
Code Example
Here’s the relevant part of the seed.ts file:
What I’ve Tried
Verified that the file exists and the path is correct.
Used tsconfig-paths to resolve path aliases:
Tried using require instead of import as a temporary workaround.
Ensured ts-node and typescript versions are compatible.
Error Details
Error: Cannot find module '@/lib/actionFlower'
Require stack:
- C:\Users\Safwan\apps\habitleaf-real\prisma\seed.ts
What could be causing this issue, and how can I ensure that ts-node correctly resolves the path aliases after restructuring the project?
Any guidance or suggestions would be greatly appreciated!
Thanks you
I’m encountering a MODULE_NOT_FOUND error when running a seed script in my project. The issue started after I restructured the project, even though the paths and configurations seem correct. Before the refactor, everything worked perfectly.
Context
I’m using ts-node to run a Prisma seed script:
ts-node --compiler-options '{"module":"CommonJS"}' prisma/seed.ts
The error occurs when trying to import a module using a path alias (@/features/garden-page/server/actionGarden).
The tsconfig.json is configured with:
"paths": {
"@/*": ["./src/*"]
}
The file structure matches the path alias:
src/
lib/
actionFlower.ts
Code Example
Here’s the relevant part of the seed.ts file:
"use server";
console.log("Seeding database...");
import { PrismaClient } from "@prisma/client";
import { initFlower } from "../src/lib/actionFlower";
const prisma = new PrismaClient();
export const initDbData = async () => {
console.log("Seeding database...");
await initFlower();
console.log("Database seeded!");
};
initDbData()
.catch((e) => {
console.log(e);
process.exit(1);
})
.finally(async () => {
await prisma.$disconnect();
});
What I’ve Tried
Verified that the file exists and the path is correct.
Used tsconfig-paths to resolve path aliases:
ts-node -r tsconfig-paths/register --compiler-options '{"module":"CommonJS"}' prisma/seed.ts
Checked for circular dependencies or misconfigurations in tsconfig.json.
Tried using require instead of import as a temporary workaround.
Ensured ts-node and typescript versions are compatible.
Error Details
Error: Cannot find module '@/lib/actionFlower'
Require stack:
- C:\Users\Safwan\apps\habitleaf-real\prisma\seed.ts
What could be causing this issue, and how can I ensure that ts-node correctly resolves the path aliases after restructuring the project?
Any guidance or suggestions would be greatly appreciated!
Thanks you