Next.js-错误构建目录在EC2上不可写 [英] Next.js - ERROR Build directory is not writeable on EC2

查看:98
本文介绍了Next.js-错误构建目录在EC2上不可写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我第一次在具有 64位Amazon Linux/4.11.0 的Elastic BeanStalk上运行带有自定义 server.js 的Next.js应用程序.

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.

在应用程序,环境和使用eb-cli进行的创建之后,我在EB仪表板中收到了一条警告环境运行状况已从已降级"变为严重" .

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.

我将 Node命令更改为 npm run deploy 的配置.什么都没改变.

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

这是我的 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"
  },

我用 eb ssh 连接到eb实例,找到项目目录后,我尝试执行 npm run build ,但是发生了错误.

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

我已经使用 sudo 创建了 .next 目录,但是仍然出现错误.

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

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

推荐答案

我在本地遇到了同样的错误,经过大约一个小时的故障排除,我意识到我的节点版本设置错误.似乎next 9.4不支持节点的版本9.我更新到了版本12,并且可以正常使用.

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.

这篇关于Next.js-错误构建目录在EC2上不可写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆