NextJS SRC to App Directory Conversion

Uncategorized

How can I convert this nextjs app from using the SRC directory to using just the APP directory and the root folder structure if we want to use best practices for nextjs14 and beyond.

GitHub Copilot: Deciding which workspace information to collect

Collecting workspace information

Filtering to most relevant information

To convert your Next.js app from using the src directory to using just the app directory and the root folder structure, you can follow these steps:

  1. Move all the files and folders from src to the app directory. This includes auth.ts, components, db, lib, types, and any other files or folders you may have in src.
  2. Update all the import paths in your project to reflect the new structure. For example, if you have an import like this in your code:
import { db } from "./src/db/index";

You should change it to:

import { db } from "./app/db/index";
  1. Update your tsconfig.json file to include the app directory in the include array:
{
  "include": ["app/**/*"],
  // rest of your tsconfig.json
}
  1. Update your next.config.js file to include the app directory in the dir option:
const nextConfig = {
  dir: "./app",
  // rest of your next.config.js
};
  1. Update your scripts in package.json to point to the app directory. For example, if you have a script like this:
"dev": "next dev src"

You should change it to:

"dev": "next dev app"
  1. Finally, test your application to make sure everything is working as expected. You can do this by running your development server with npm run dev (or yarn dev, pnpm dev, bun dev depending on your package manager) and navigating to http://localhost:3000 in your browser.

Remember to commit your changes to version control after verifying that everything works as expected.

Leave a Comment