Кодовый конвейер AWS для веб-сайта Next.js на Elastic Beanstalk

У меня Codepipeline отлично работает с

  1. Извлечь исходные файлы из Github
  2. Создайте рабочий сайт Next.js на Codebuild и выведите его на 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! [email protected] 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.


person user1791914    schedule 26.10.2020    source источник


Ответы (1)


Добавьте npm install next -g в команды phase.index.com, что позволит контейнеру распознавать 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:
     - '**/*'
person prosunshining    schedule 26.10.2020
comment
Я не полностью слежу. Это входит в buildspec.yml? - person user1791914; 27.10.2020
comment
команды: - yarn - npm install next -g Да, npm install next -g под пряжей - person prosunshining; 27.10.2020