Unverified Commit 8cd6bd3f authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Add check for writeable directory (#3370)

* Add check for writeable directory

Followup of https://github.com/zeit/now-cli/issues/175

* Add link to docs
parent 57c6f80d
# 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)
...@@ -669,7 +669,19 @@ export default ({ url }) => ...@@ -669,7 +669,19 @@ export default ({ url }) =>
</ul> </ul>
</details></p> </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`: This example makes `/a` resolve to `./pages/b`, and `/b` resolve to `./pages/a`:
......
...@@ -10,6 +10,14 @@ import md5File from 'md5-file/promise' ...@@ -10,6 +10,14 @@ import md5File from 'md5-file/promise'
export default async function build (dir, conf = null) { export default async function build (dir, conf = null) {
const buildId = uuid.v4() const buildId = uuid.v4()
const buildDir = join(tmpdir(), 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 }) const compiler = await webpack(dir, { buildId, buildDir, conf })
try { try {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment