This project is a Next.js starter kit, which includes all the base tooling needed for a React project using Next.js.
Project Includes:
- TypeScript configs
- ESLint
- Prettier auto-formatting
- Automatic lint checks using lint-staged and Husky
- Sentry error logging
npx create-next-app@latest --typescript
to install the base Next.js project with TypeScriptnpm run lint
runs ESLint for the first time and configures the "next/core-web-vitals" extension.npm install --save-dev eslint-config-prettier
to configure ESLint ant Prettier to work together.- Add "prettier" to the ESLint config.
- Add a the
.prettierrc
config file with the following default configurations:
{
"printWidth": 120,
"tabWidth": 4
}
- Install Husky and lint-staged with
npm install --save-dev husky lint-staged
- Add script to
package.json
to install Husky:"prepare": "husky install"
- Add
.lintstagedrc.js
and copy and paste config from this Next.js documentation. - Run script to install Husky:
npm run prepare
- Add the following lint-staged config to
package.json
:
"lint-staged": {
"*.{ts,js,tsx,jsx}": "eslint --cache --fix",
"*.{ts,js,tsx,jsx,css,md,json}": "prettier --write"
}
- Add a precommit hook to run lint-staged on every git commit:
npx husky add .husky/pre-commit "npx lint-staged"
- Add Sentry package:
npm install --save @sentry/nextjs
- Install the project dependencies:
npm i
- Go to https://sentry.io/organizations/vacayou/projects/new/ to add a new project
- Select Next.js as the platform
- Configure your desired settings, then click "Create Project"
- Run the "Sentry Wizard" command to setup the project:
npx @sentry/wizard -i nextjs
- Follow the steps for the Sentry Wizard, and resolve any file merges that may come up.
- Wrap your API handlers with a withSentry function to capture Next.js API route errors. See the example in
/pages/api/hello.ts
npm run dev
# or
yarn dev
Open http://localhost:3000 with your browser to see the result.
You can start editing the page by modifying pages/index.tsx
. The page auto-updates as you edit the file.
API routes can be accessed on http://localhost:3000/api/hello. This endpoint can be edited in pages/api/hello.ts
.
The pages/api
directory is mapped to /api/*
. Files in this directory are treated as API routes instead of React pages.
To learn more about Next.js, take a look at the following resources:
- Next.js Documentation - learn about Next.js features and API.
- Learn Next.js - an interactive Next.js tutorial.
You can check out the Next.js GitHub repository - your feedback and contributions are welcome!
The easiest way to deploy your Next.js app is to use the Vercel Platform from the creators of Next.js.
Check out our Next.js deployment documentation for more details.