我有一个功能正常的React Web应用程序,它部署在Heroku上。我正在尝试将整个应用程序迁移到AWS,但我遇到了一些麻烦。我首先尝试创建一个EC2实例并在那里克隆我的github repo。我无法让这个工作。我认为这是因为只有服务器端代码应该添加到EC2实例而不是客户端。
我现在正在尝试使用Elastic Beanstalk上传我的代码(服务器和客户端)。这个过程看起来非常简单,但是当我上传我的.zip文件并部署时,我在事件日志中收到以下错误:
无法找到package.json。 Node.js可能会出现问题。验证package.json是否有效或将代码放在名为server.js或app.js的文件中。
我的zip文件夹中有一个package.json
文件,所以我真的不确定这里发生了什么。对此有任何建议会有所帮助。
以下是我的package.json
的内容:
{
"name": "beer",
"version": "0.1.0",
"private": true,
"proxy": "http://localhost:5000",
"dependencies": {
"@fortawesome/fontawesome-svg-core": "^1.2.12",
"@fortawesome/free-solid-svg-icons": "^5.6.3",
"@fortawesome/react-fontawesome": "^0.1.3",
"@material-ui/core": "^3.8.1",
"@material-ui/icons": "^3.0.1",
"aws-sdk": "^2.422.0",
"axios": "^0.18.0",
"bcrypt": "^3.0.4",
"body-parser": "^1.18.3",
"cookie-session": "^2.0.0-beta.3",
"dotenv": "^4.0.0",
"express": "^4.16.4",
"material-ui-rating": "^2.0.0",
"passport": "^0.4.0",
"passport-local": "^1.0.0",
"pg": "^7.8.0",
"react": "^16.7.0",
"react-dom": "^16.7.0",
"react-redux": "^6.0.0",
"react-router-dom": "^4.3.1",
"react-scripts": "2.1.2",
"redux": "^4.0.1",
"redux-logger": "^3.0.6",
"redux-saga": "^0.16.2",
"session-middleware": "^1.0.2",
"sweetalert": "^2.1.2"
},
"scripts": {
"start": "node server/server.js",
"client": "react-scripts start",
"server": "nodemon --watch server server/server.js",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
]
}
和我的zip文件结构:
--beer
-build
-nodemodules
-package.json
-public
-index.html
-manifest.json
-server
-server.js
-modules
-routes
-src
-index.js
-components
-App
-App.js
-redux
-reducers
-index.js
-sagas
index.js
使用zip文件部署到Elastic Beanstalk时,必须确保使用zip doesn't contain a top-level container directory。在您的情况下,您的beer/
目录不能包含在内。
在macOS或Windows上你可以select the contents of your beer/
directory and compress them。如果您上传没有顶级目录的新zip,Elastic Beanstalk应该能够找到您的package.json
文件并正确部署您的应用程序。