Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to change where Next looks for pages? #2202

Closed
bookercodes opened this issue Jun 8, 2017 · 4 comments
Closed

How to change where Next looks for pages? #2202

bookercodes opened this issue Jun 8, 2017 · 4 comments

Comments

@bookercodes
Copy link

bookercodes commented Jun 8, 2017

So, I am wanting to build a Next app with T$.

To do that, I install typescript and compile my Next app into a bin directory:

+ bin/
  + server.js
  + pages/
    + index.js
+ server.js
+ pages/
+ index.tsx
+ package.json

In package.json, I have a script: node bin/server.js. When I run said script, Next will look in ./pages instead of ./bin/pages (i.e. from the cwd not __dirname). To work around this, I have to cd into bin before running node ./server.js (a one-line would be (cd ./bin && node ./server), if you're reading this and you need a work-around)

It it possible to configure where Next looks for pages?

@sergiodxa
Copy link
Contributor

sergiodxa commented Jun 8, 2017

When you create your custom server you can pass a argument dir to next.

const next = require('next')
const dev = process.env.NODE_ENV !== 'production'
const app = next({ dir: './bin', dev })

Next.js it's going to use ./bin to look for pages directory. If you don't have a custom server then you can run next ./bin.

@bookercodes
Copy link
Author

bookercodes commented Jun 8, 2017

Ah, that is exactly what I was looking for but couldn't find in the docs 😢

Nice one mate, thank you!

@jonathanrz
Copy link

jonathanrz commented Jan 18, 2018

I followed the idea of specifying the dir property for the next app and it worked, thanks.

But when I run yarn next build, it crashes with the message:

> Couldn't find a `pages` directory. Please create one under the project root error Command failed with exit code 1.

How can I specify the pages directory when running the build task?

--EDIT--
Found the solution here: #819
The solution is to pass the path as a parameter for the build task, in the example provided the solution would be yarn next build bin

@lock lock bot locked as resolved and limited conversation to collaborators Jan 18, 2019
@timneutkens
Copy link
Member

Posted #8451

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants