【问题标题】:AWS codepipeline for Next.js website on Elastic Beanstalk用于 Elastic Beanstalk 上 Next.js 网站的 AWS 代码管道
【发布时间】:2021-02-08 22:49:39
【问题描述】:

我的 Codepipeline 非常适合

  1. 从 Github 拉取源文件
  2. 在 Codebuild 上构建一个正常工作的 Next.js 网站并输出到 S3
  3. 根据Codedeploy,部署S3文件Elastic Beanstalk时有成功

但是,一旦 Elastic Beanstalk 尝试运行,我就会遇到问题。

Oct 26 15:55:23 ip-xxx-xx-xx-xxx web: code: 'MODULE_NOT_FOUND',
Oct 26 15:55:23 ip-xxx-xx-xx-xxx web: requireStack: [ '/var/app/current/node_modules/.bin/next' ]
Oct 26 15:55:23 ip-xxx-xx-xx-xxx web: }
Oct 26 15:55:23 ip-xxx-xx-xx-xxx web: npm ERR! code ELIFECYCLE
Oct 26 15:55:23 ip-xxx-xx-xx-xxx web: npm ERR! errno 1
Oct 26 15:55:23 ip-xxx-xx-xx-xxx web: npm ERR! with-typescript@1.0.0 start: `next start`
Oct 26 15:55:23 ip-xxx-xx-xx-xxx web: npm ERR! Exit status 1

我的启动命令是next start,但似乎节点模块不存在。当我在 S3 中解压缩输出时,我看到了完整的 next.js 构建,所以这部分看起来还不错。我似乎无法找到为什么它不能在 ELB 上运行的解决方案——知道哪里出了问题吗?下面是我的buildspec.yml,供参考。

version: 0.2

phases:
  install:
    #If you use the Ubuntu standard image 2.0 or later, you must specify runtime-versions.
    #If you specify runtime-versions and use an image other than Ubuntu standard image 2.0, the build fails.
    runtime-versions:
       nodejs: 12
    commands:
       - yarn
  build:
    commands:
       - npx next build
artifacts:
  files:
     - '**/*'

更新

事实证明,一切就绪,但无法识别“下一个”命令。解决方案是在我的启动命令中使用绝对路径:node_modules/next/dist/bin/next start

【问题讨论】:

    标签: node.js amazon-elastic-beanstalk next.js aws-codepipeline aws-codebuild


    【解决方案1】:

    在phases.index.commands中添加npm install next -g,这将使容器识别next

    version: 0.2
    
    phases:
      install:
        #If you use the Ubuntu standard image 2.0 or later, you must specify runtime-versions.
        #If you specify runtime-versions and use an image other than Ubuntu standard image 2.0, the build fails.
        runtime-versions:
           nodejs: 12
        commands:
           - yarn
           - npm install next -g
      build:
        commands:
           - npx next build
    artifacts:
      files:
         - '**/*'
    

    【讨论】:

    • 我没有完全关注。这会进入 buildspec.yml 吗?
    • 命令:- yarn - npm install next -g 是的,npm install next -g 在 yarn 下面
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-04-09
    • 1970-01-01
    • 2020-11-24
    • 2019-05-11
    • 2023-03-10
    • 2019-10-30
    • 2020-10-17
    相关资源
    最近更新 更多