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

試著忘記壹切 提交于 2021-01-28 19:09:35

问题


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


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/58614922/next-js-error-build-directory-is-not-writeable-on-ec2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!