Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

1.4K
Views
Couldn't find a `pages` directory. NextJS with pkg

I want to make a NextJS executable app for Windows, but I get this annoying error:

(node:18500) UnhandledPromiseRejectionWarning: Error: > Couldn't find a pages directory. Please create one under the project root

I have a pages folder in the root folder

Below is server.js

const { createServer } = require('http')
const next = require('next')

const port = parseInt(process.env.PORT, 10) || 3003
const dev = process.env.NODE_ENV !== 'production'
const app = next({ dev, dir: __dirname })
const handle = app.getRequestHandler()

app.prepare().then(() => {
  createServer((req, res) => {
    const parsedUrl = new URL(req.url, 'http://w.w')
    const { pathname, query } = parsedUrl

    if (pathname === '/a') {
      app.render(req, res, '/a', query)
    } else if (pathname === '/b') {
      app.render(req, res, '/b', query)
    } else {
      handle(req, res, parsedUrl)
    }
  }).listen(port, (err) => {
    if (err) throw err
    console.log(`> Ready on http://localhost:${port}`)
  })
})

And package.json

{
  "name": "custom-server",
  "version": "1.0.0",
  "scripts": {
    "dev": "node server.js",
    "build": "next build",
    "start": "cross-env NODE_ENV=production node server.js",
    "pkg": "pkg . --targets node12-win-x64 --out-path pkg"
  },
  "dependencies": {
    "cross-env": "^7.0.2",
    "next": "latest",
    "pkg": "^4.4.9",
    "react": "^17.0.1",
    "react-dom": "^17.0.1"
  },
  "main": "server.js",
  "license": "MIT",
  "bin": "server.js",
  "pkg": {
    "assets": [
      ".next/**/*"
    ],
    "scripts": [
      ".next/server/**/*.js"
    ]
  }
}

How can I solve this issue and make a NextJS working executable ?

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!