我有一个运行正常的React Web应用程序,该应用程序已部署在Heroku上。我正在尝试将整个应用程序迁移到AWS,但遇到了一些麻烦。我首先尝试创建一个EC2实例,并在那里克隆我的github存储库。我无法使它正常工作。我认为这是因为仅应将服务器端代码添加到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
答案 0 :(得分:1)
在使用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
文件并正确部署您的应用程序。