reactjsnext.jsvitemonoreponx-monorepo

AWS amplify not recognizing vite react NX monorepo


I have a new NX monorepo with 3 apps. Two of them are bundled with Vite and one is a NextJS project.

When I deploy the vite app to AWS Amplify it recognizes the app folder as NextJS-SSR! It also throws the error

CustomerError: Can't find required-server-files.json in build output directory

Vite | amplify.yml

version: 1
applications:
  - frontend:
      phases:
        preBuild:
          commands:
            - npm ci
        build:
          commands:
            - npx nx build vite-app
      artifacts:
        baseDirectory: dist/apps/vite-app
        files:
          - '**/*'
      cache:
        paths:
          - node_modules/**/*
      buildPath: /
    appRoot: apps/vite-app

Note

If I remove the NextJS app using nx remove nextjs-app and deploy to AWS Amplify with just the vite apps. The app deploys correctly.

I don't understand why Amplify is recognizing the app as NextJS and how to get rid off it. I need to deploy two applications with vite and two with nextjs.

P.S: I can provide more info if needed!

Edit

NextJS | amplify.yml

version: 1
applications:
  - frontend:
      phases:
        preBuild:
          commands:
            - node -v
            - npm ci
        build:
          commands:
            - npx nx build nextjs-app
      artifacts:
        baseDirectory: dist/apps/nextjs-app
        files:
          - '**/*'
      cache:
        paths:
          - .next/cache/**/*
          - node_modules/**/*
      buildPath: /
    appRoot: apps/nextjs-app

The Nextjs project is deployed successfully without any issues.


Solution

  • I talked to AWS Support and they gave me a work around rather than a proper solution but its working fine so I am sharing it for the next person who runs into this issue.

    I created a Vite/ReactJS apps and deployed them to AWS Amplify. Business as usual. Then I created and deployed the NextJS app which also worked as intended.

    Now, I created and deployed the second Vite/ReactJS app but before deploying it for the first time. I had to move the nextjs dependency in package.json from dependencies to dev-dependencies. Then deploy the app to AWS Amplify. It worked for me. After that I moved the nextjs dependency back from dev-dependencies to dependencies. All subsequent deploys are working as intended.

    Any time you need to a add new Vite/ReactJS app to your repository you will need to follow this process, only the first time.