現象
next.js/examples/custom-server-typescript at canary · zeit/next.js
上記のcustom-server-typescriptに近い環境。
Docker内で.next
や.dist
をコピーして元のpages
やsrc
はない状態。
起動すると以下のようなエラーが発生する。
frontend_1 | /node_modules/next/dist/lib/find-pages-dir.js:3
frontend_1 | if(existsSync(_path.default.join(dir,'..','pages'))){throw new Error('> No `pages` directory found. Did you mean to run `next` in the parent (`../`) directory?');}throw new Error("> Couldn't find a `pages` directory. Please create one under the project root");}
frontend_1 | ^
frontend_1 |
frontend_1 | Error: > Couldn't find a `pages` directory. Please create one under the project root
frontend_1 | at findPagesDir (/node_modules/next/dist/lib/find-pages-dir.js:3:170)
frontend_1 | at new DevServer (/node_modules/next/dist/server/next-dev-server.js:1:3830)
frontend_1 | at Object.createServer [as default] (/node_modules/next/dist/server/next.js:2:105)
frontend_1 | at Object.<anonymous> (/dist/server/server.js:11:27)
frontend_1 | at Module._compile (internal/modules/cjs/loader.js:1158:30)
frontend_1 | at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
frontend_1 | at Module.load (internal/modules/cjs/loader.js:1002:32)
frontend_1 | at Function.Module._load (internal/modules/cjs/loader.js:901:14)
frontend_1 | at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
frontend_1 | at internal/main/run_main_module.js:18:47
解決
NODE_ENV=production
が必要。指定すると解決。