In a create-next-app
Next.js application, I want to move the pages
folder in the root directory to a src
folder. I added a jsconfig.json
with the code (below), however now I get the error message "404 | This page could not be found." Anyone have any insight? (Sorry beginner to web development)
{
"compilerOptions": {
"baseUrl": "src"
}
}
Nextjs by default supports moving /pages
to src/
folder.
/.next
folder/pages
to the /src folder
Remember package.json, .gitignore
and other config files needs to be in the root directory and should not be moved to the /src folder.Once that is done just run the command $ npm run dev
or $ yarn dev
, so you can view it on your localhost.
More: https://nextjs.org/docs/advanced-features/src-directory
In case you are using NextJS + TailwindCSS, you need to change the following in tailwind.config.js
after moving files under the src
directory:
module.exports = {
content: [
'./pages/**/*.{js,ts,jsx,tsx}',
'./components/**/*.{js,ts,jsx,tsx}',
],
...
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With