【发布时间】:2021-05-02 00:03:13
【问题描述】:
尝试在弹性 beanstalk 上启动 react 节点应用程序并遇到服务器端错误
我的文件夹设置是
-client
-server
- index.js
- other files etc
-package.json
在我的 package.json 中,我的脚本被列为
{
"version": "0.0.0",
"main": "dist/index.js",
"scripts": {
"clean": "rm -rf build && mkdir build",
"build-server": "babel -d ./build ./server -s",
"build": "npm run clean && npm run build-server",
"start": "npm run build && node ./build/index.js",
},
"dependencies": {
"@babel/runtime": "^7.9.2",
},
"devDependencies": {
"@babel/cli": "^7.5.5",
"@babel/core": "^7.5.5",
"@babel/node": "^7.5.5",
"@babel/plugin-proposal-class-properties": "^7.5.5",
"@babel/plugin-proposal-decorators": "^7.4.4",
"@babel/plugin-transform-runtime": "^7.9.0",
"@babel/preset-env": "^7.5.5",
"@babel/preset-react": "^7.0.0",
"babel-eslint": "^10.0.2",
"babel-loader": "^8.0.6",
"nodemon": "^2.0.7"
}
}
运行 eb deploy 时出现错误
Jan 28 04:51:45 web: > api@0.0.0 start /var/app/current
Jan 28 04:51:45 web: > npm run build && node ./build/index.js
Jan 28 04:51:45 web: > api@0.0.0 build /var/app/current
Jan 28 04:51:45 web: > npm run clean && npm run build-server
Jan 28 04:51:45 web: > api@0.0.0 clean /var/app/current
Jan 28 04:51:45 web: > rm -rf build && mkdir build
Jan 28 04:51:45 web: > api@0.0.0 build-server /var/app/current
Jan 28 04:51:45 web: > babel -d ./build ./server -s
Jan 28 04:51:45 web: sh: babel: command not found
不确定如何解决这个问题,因为我的 package.json 已经包含 babel 依赖项
另外,从其他在线教程中,我看到指南声明将 index.js 输出为编译文件,并包括一个覆盖 npm start 并运行编译文件的 Procfile,但这种方法对我不起作用,因为我的服务器包含 10+文件。
"babel index.js --out-file index-compiled.js",
任何帮助表示赞赏。谢谢
【问题讨论】:
-
你的 Babel 依赖是在 dependencies 还是 devDependencies 中,哪个在 EB 上使用?通常你会提前编译,而不是在服务器上。 “这种方法行不通”是什么意思?您在启动前执行完全相同的操作(构建服务器脚本),您通常只是将其作为构建过程的一部分。
-
添加了我的依赖项,我也尝试过,但最终出现不同的错误,“找不到模块”
标签: node.js amazon-web-services express babeljs amazon-elastic-beanstalk