Skip to content

Commit

Permalink
Add check for writeable directory (vercel#3370)
Browse files Browse the repository at this point in the history
* Add check for writeable directory

Followup of vercel/vercel#175

* Add link to docs
  • Loading branch information
timneutkens authored Dec 2, 2017
1 parent 57c6f80 commit 8cd6bd3
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
30 changes: 30 additions & 0 deletions errors/build-dir-not-writeable.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Build directory not writeable

#### Why This Error Occurred

The filesystem does not allow writing to the specified directory. A common cause for this error is starting a [custom server](https://github.com/zeit/next.js#custom-server-and-routing) in development mode on a production server, for example, [now.sh](https://zeit.co) which [doesn't allow you to write to the filesystem after your app is built](https://zeit.co/docs/deployment-types/node#file-system-specifications).

#### Possible Ways to Fix It

When using a custom server with a server file, for example called `server.js`, make sure you update the scripts key in `package.json` to:

```json
{
"scripts": {
"dev": "node server.js",
"build": "next build",
"start": "NODE_ENV=production node server.js"
}
}
```

and the custom server starts Next in production mode when `NODE_ENV` is `production`

```js
const dev = process.env.NODE_ENV !== 'production'
const app = next({ dev })
```

### Useful Links

- [Custom Server documentation + examples](https://github.com/zeit/next.js#custom-server-and-routing)
14 changes: 13 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,19 @@ export default ({ url }) =>
</ul>
</details></p>

Typically you start your next server with `next start`. It's possible, however, to start a server 100% programmatically in order to customize routes, use route patterns, etc
Typically you start your next server with `next start`. It's possible, however, to start a server 100% programmatically in order to customize routes, use route patterns, etc.

When using a custom server with a server file, for example called `server.js`, make sure you update the scripts key in `package.json` to:

```json
{
"scripts": {
"dev": "node server.js",
"build": "next build",
"start": "NODE_ENV=production node server.js"
}
}
```

This example makes `/a` resolve to `./pages/b`, and `/b` resolve to `./pages/a`:

Expand Down
8 changes: 8 additions & 0 deletions server/build/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ import md5File from 'md5-file/promise'
export default async function build (dir, conf = null) {
const buildId = uuid.v4()
const buildDir = join(tmpdir(), uuid.v4())

try {
await fs.access(buildDir, fs.constants.W_OK)
} catch (err) {
console.error(`> Failed, build directory is not writeable. https://err.sh/zeit/next.js/build-dir-not-writeable`)
throw err
}

const compiler = await webpack(dir, { buildId, buildDir, conf })

try {
Expand Down

0 comments on commit 8cd6bd3

Please sign in to comment.