node.js - 找不到任何nodejs模块AWS Elastic Beanstalk

标签 node.js amazon-web-services amazon-elastic-beanstalk aws-codebuild

我正在尝试将我的 Express 服务器部署到 AWS Elastic Beanstalk,但一直遇到找不到模块的问题。我正在使用 CodeBuild 和 buildspec.yml 来构建我的代码并将其转换为工件。

EB 部署日志:

----------------------------------------
/var/log/web.stdout.log
----------------------------------------
Sep 12 22:54:02 ip-172-31-15-80 web: at Function.Module._load (node:internal/modules/cjs/loader:839:12)
Sep 12 22:54:02 ip-172-31-15-80 web: at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) {
Sep 12 22:54:02 ip-172-31-15-80 web: code: 'MODULE_NOT_FOUND',
Sep 12 22:54:02 ip-172-31-15-80 web: requireStack: [ '/var/app/current/app.js' ]
Sep 12 22:54:02 ip-172-31-15-80 web: }
Sep 12 22:54:02 ip-172-31-15-80 web: node:internal/modules/cjs/loader:959
Sep 12 22:54:02 ip-172-31-15-80 web: throw err;
Sep 12 22:54:02 ip-172-31-15-80 web: ^
Sep 12 22:54:02 ip-172-31-15-80 web: Error: Cannot find module 'express'
Sep 12 22:54:02 ip-172-31-15-80 web: Require stack:
Sep 12 22:54:02 ip-172-31-15-80 web: - /var/app/current/app.js
Sep 12 22:54:02 ip-172-31-15-80 web: at Function.Module._resolveFilename (node:internal/modules/cjs/loader:956:15)
Sep 12 22:54:02 ip-172-31-15-80 web: at Function.Module._load (node:internal/modules/cjs/loader:804:27)
Sep 12 22:54:02 ip-172-31-15-80 web: at Module.require (node:internal/modules/cjs/loader:1028:19)
Sep 12 22:54:02 ip-172-31-15-80 web: at require (node:internal/modules/cjs/helpers:102:18)
Sep 12 22:54:02 ip-172-31-15-80 web: at Object.<anonymous> (/var/app/current/app.js:6:35)
Sep 12 22:54:02 ip-172-31-15-80 web: at Module._compile (node:internal/modules/cjs/loader:1126:14)
Sep 12 22:54:02 ip-172-31-15-80 web: at Object.Module._extensions..js (node:internal/modules/cjs/loader:1180:10)
Sep 12 22:54:02 ip-172-31-15-80 web: at Module.load (node:internal/modules/cjs/loader:1004:32)
Sep 12 22:54:02 ip-172-31-15-80 web: at Function.Module._load (node:internal/modules/cjs/loader:839:12)
Sep 12 22:54:02 ip-172-31-15-80 web: at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) {
...

构建规范.yml

version: 0.2

batch:
  fast-fail: true
phases:
  install:
    runtime-versions:
      nodejs: 16
  build:
    commands:
      - npm run build
artifacts:
  type: zip
  files:
    - "**/*"
  base-directory: build

任何帮助将不胜感激。

最佳答案

您需要在构建步骤中复制node_modules。我的方法是添加一个 post_build pahase。

post_build:
    commands:
        - cp -R node_modules/ dist/node_modules

关于node.js - 找不到任何nodejs模块AWS Elastic Beanstalk,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73696099/

相关文章:

amazon-web-services - Go lang 中的 AWS API Gateway 客户端证书

amazon-web-services - 如何使用 cloudformation 模板为 Elastic Beanstalk 启用 CloudWatch

java - 环境变量在 Elastic Beanstalk Procfile 中不可用

node.js - 可以跟踪正在使用的应用程序以及使用 Node.js 打开的文件

shell - 并发批处理作业将日志写入数据库

angularjs - 在nodejs环回中安排一个cron作业

amazon-web-services - 添加作为服务相关角色的 IAM 角色

spring-boot - JAR 中的 Spring Boot + Elastic Beanstalk .ebextensions

node.js - 错误 : Cannot find module 'babel-register'

node.js - Graphql 仅在传递参数时执行 where 条件