shuding / nextra

Simple, powerful and flexible site generation framework with everything you love from Next.js.
https://nextra.site
MIT License
11.71k stars 1.27k forks source link

Error: Couldn't find a `pages` directory. #1891

Open sandervspl opened 1 year ago

sandervspl commented 1 year ago

next start can not run if there is no pages folder present in the root directory. It should be able to run without a pages folder.

How to reproduce

  1. run npx create-next-app@latest

TypeScript: Yes ESLint: No Tailwind: No src directory: Yes App Router: No customize import alias: No

  1. Run npm i nextra nextra-theme-docs
  2. Run npm run build
  3. Copy the following directories/files to another directory:
    • .next
    • public
    • next.config.js
    • package.json
    • package-lock.json
  4. Run npm install
  5. Run npm start

You should see the following error

> next start

/Documents/throwaways/nextra-pages-dir/node_modules/next/dist/lib/find-pages-dir.js:104
            throw new Error("> Couldn't find a `pages` directory. Please create one under the project root");
                  ^

Error: > Couldn't find a `pages` directory. Please create one under the project root
    at findPagesDir (/Documents/throwaways/nextra-pages-dir/node_modules/next/dist/lib/find-pages-dir.js:104:19)
    at findPagesDirectory (/Documents/throwaways/nextra-pages-dir/node_modules/nextra/dist/index.js:157:15)
    at Object.<anonymous> (/Documents/throwaways/nextra-pages-dir/node_modules/nextra/dist/index.js:161:53)
    at Module._compile (node:internal/modules/cjs/loader:1191:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1245:10)
    at Module.load (node:internal/modules/cjs/loader:1069:32)
    at Function.Module._load (node:internal/modules/cjs/loader:904:12)
    at Module.require (node:internal/modules/cjs/loader:1093:19)
    at require (node:internal/modules/cjs/helpers:108:18)
    at Object.<anonymous> (/Documents/throwaways/nextra-pages-dir/next.config.js:1:20)

When you add an empty pages folder it works again.

I have tried running a regular Next server (so, without Nextra) and it will run without a pages folder.

dimaMachina commented 1 year ago

It should be able to run without a pages folder.

what is the purpose of building your app without pages folder?

Nextra requires pages folder to be present

more info https://github.com/shuding/nextra/discussions/1142#discussioncomment-4552759

sandervspl commented 1 year ago

Well, when you run "next build" your app is compiled into the ".next" folder. That is what I presume to be the entire app. A regular Next app works with just the ".next" folder after you build it. You can leave out the "pages" folder because that is only necessary for development.

That is not the case with Nextra. I need to add an empty "pages" folder for the production server to run.

I have updated the initial post to specify next start. Obviously you need a pages folder for dev, but for next start you don't need one because it's all compiled in to .next

dimaMachina commented 1 year ago

If somebody wants to improve it, feel free to contribute

morandalex commented 1 year ago

how specify the pages directory? for example, if I am using electron, the pages folder is inside renderer folder.

dimaMachina commented 1 year ago

what's renderer folder? provide an example