Next.js: custom page dir

Created on 14 Jan 2018  路  6Comments  路  Source: vercel/next.js

  • [x ] I have searched the issues of this repository and believe that this is not a duplicate.

Expected Behavior

run without any error

Current Behavior

work good with node server.js
but with: next export got error Couldn't find apagesdirectory. Please create one under the project root

Steps to Reproduce (for bugs)


  1. move pages to ./src
  2. create server.js
  3. add the code: const app = next({ dev, dir: './src' });
  4. run: "export": "next export"

Your Environment

| Tech | Version |
|---------|---------|
| next | 4.2.1 |
| node | v7.6.0 |
| OS | window 8.1 |
| browser | chrome |

Most helpful comment

@krasevych I got this to work as follows:

Add to src/next.config.js:

module.exports = {
  exportPathMap() {
    return {
      '/': { page: '/' },
      '/about': { page: '/about' },
    }
  },

Add 'src' directory to package.json scripts:

  "scripts": {
    "dev": "next src",
    "build": "next build src",
    "start": "next start src",
    "export": "next build src && next export src",

yarn export produces a static build in src/out

All 6 comments

@krasevych I got this to work as follows:

Add to src/next.config.js:

module.exports = {
  exportPathMap() {
    return {
      '/': { page: '/' },
      '/about': { page: '/about' },
    }
  },

Add 'src' directory to package.json scripts:

  "scripts": {
    "dev": "next src",
    "build": "next build src",
    "start": "next start src",
    "export": "next build src && next export src",

yarn export produces a static build in src/out

dir is a next.js app root. So you need to have pages in src/pages.

@timneutkens but I wrote move pages to ./src, that means I have page in ./src/pages

Ah, sorry @krasevych I understood it as: moved pages to src as in mv -r pages/* src, which wouldn't work 馃槈 i'll check your issue out after v5 is released 馃憤

Actually you're confusing 2 things. next export doesn't use the custom server. @gihrig's explanation is correct. You need to provide the dir to next build and next export. Then it'll work 馃憤

@gihrig @timneutkens thanks!

Was this page helpful?
0 / 5 - 0 ratings