简体   繁体   中英

Next.js - ERROR Build directory is not writeable on EC2

I'm running for the first time my Next.js app with a custom server.js on Elastic BeanStalk with 64bit Amazon Linux/4.11.0 .

After the creation on the application, the environment and the deploy with the eb-cli I received a warning into the EB dashboard Environment health has transitioned from Degraded to Severe .

I changed the Node command into the config to npm run deploy . Nothing changed.

Here's my package.json .

"scripts": {
    "start": "pm2 start server.js -i max",
    "build": "next build",
    "dev": "nodemon --exec babel-node server.js",
    "start-next": "next start",
    "deploy": "NODE_ENV=production next build && pm2 start server.js -i max",
    "test": "echo \"Error: no test specified\" && exit 1"
  },

I connected to the eb instance with eb ssh and after I've located the project dir I tried to execute npm run build but an error happened.

> NODE_ENV=production next build && pm2 start server.js -i max

> Build error occurred
Error: > Build directory is not writeable. https://err.sh/zeit/next.js/build-dir-not-writeable
    at build (/var/app/current/node_modules/next/dist/build/index.js:1:6361)
    at <anonymous>
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! webreader-client@1.0.0 deploy: `NODE_ENV=production next build && pm2 start server.js -i max`
npm ERR! Exit status 1

I've created a .next directory with sudo but the error is still raised.

Docs: https://github.com/zeit/next.js/blob/master/errors/build-dir-not-writeable.md

I was getting this same error locally and after about an hour of troubleshooting, I realized I had my node version set wrong. Seems like next 9.4 doesn't support version 9 of node. I updated to version 12 and it's working without issue.

After spending nearly 4 hours on the phone with AWS support, their solution was as follows:

create a folder/file in the root of your project: .ebextensions/00_dir_permission.config

commands:
  01_set_file_permissions:
    command: "chmod 777 -R /tmp"

Of course this is less than ideal, but for some reason right now in EB permissions have changed such that you are not able to kick off the build without tweaking on permissions like this. Hoping this changes soon.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM