aws-amplify / amplify-hosting

AWS Amplify Hosting provides a Git-based workflow for deploying and hosting fullstack serverless web applications.
https://aws.amazon.com/amplify/hosting/
Apache License 2.0
448 stars 113 forks source link

Nextjs Turbo Monorepo 500 Error #3179

Closed Rafcin closed 1 year ago

Rafcin commented 1 year ago

Before opening, please confirm:

App Id

d2t18tt2z5krry

AWS Region

ca-central-1

Amplify Hosting feature

Build settings, Deployments, Frontend builds, Monorepo

Describe the bug

Howdy, I've discovered a bug with the new build system I had previously not thought to test. One of my main projects uses a monorepo structure. After some tinkering and dealing with the nightmare of a package manager known as pnpm, I seem unable to deploy the app; however, it builds correctly, and I can't trace the issue. The app builds correctly, finishes caching, and does all its post-build steps; it finds the correct .next folder, and then when I check the amplify domain, I get thrown a 500 error.

Expected behavior

I should be able to see my app working just fine; I think this could be the next standalone issue, although I'm wildly unsure.

Reproduction steps

I don't have a demo that can be used yet; I need to spin up a separate barebones version of my repo for this. However, my structure follows the Amplify-UI repo structure and rollup config almost the same way. The main difference is I have an apps folder, and all my apps locally reference the packages and not from npm because they aren't published. I also use hoist and auto peers shamefully...

If the Amplify team needs access to the repo, mention me, and I'll send you an invite over git.

Build Settings

Here is the Amplify YML config, you can ignore the `apps/main` section, that's old. `apps/help` is the new config.

  version: 1
  applications:
    - appRoot: apps/main
      env:
      variables:
        #AMPLIFY_DIFF_DEPLOY: true
      backend:
        phases:
          build:
            commands:
              - echo BACKEND MAIN BUILD
              - amplifyPush --simple
      frontend:
        phases:
          preBuild:
            commands:
              - echo FRONTEND MAIN PREBUILD
              # - node -e
              # - 'console.log(v8.getHeapStatistics().total_available_size/(1024*1024))'
              # Step out
              - cd ../../
              # We don't need to move folders, we already moved out to the root at the backend build step.
              #- nvm install 18
              - npx pnpm install
          build:
            commands:
              - echo FRONTEND MAIN BUILD
              # - aws s3 cp amplify.yml s3://main-sandbox/public/
              # - yarn amplify:clean:current-backend
              - npx pnpm run main:build
              # Step in
              - cd apps/main
          postBuild:
            commands:
              - echo END OF HELP BUILD
        artifacts:
          baseDirectory: .next
          files:
            - "**/*"
        cache:
          paths:
            - node_modules/**/*
            #- '!node_modules/.cache'
            #- '!.next/**/*'
    - appRoot: apps/help
      env:
      variables:
        #AMPLIFY_DIFF_DEPLOY: true
      backend:
        phases:
          build:
            commands:
              - echo NO BACKEND BUILD
      frontend:
        phases:
          preBuild:
            commands:
              - echo FRONTEND HELP PREBUILD
              - cd ../../
              - nvm install 16.13 # NodeJS 16.13+ is the latest version that Amplify Hosting supports
              - nvm use 16
              - node -v
              - echo -e "@oxygen:registry=https://registry.npmjs.org/\nstrict-peer-dependencies=false\nauto-install-peers=true\nshamefully-hoist=true" > .npmrc
          build:
            commands:
              - echo FRONTEND HELP BUILD
              # Cleans all pkg and app folders of nm, turbo, dist and .next
              - ./scripts/clean.sh
              - nvm install 16.13 # NodeJS 16.13+ is the latest version that Amplify Hosting supports
              - nvm use 16
              - node -v
              - npx pnpm install
              # - aws s3 cp amplify.yml s3://main-sandbox/public/
              # - yarn amplify:clean:current-backend
              - npx pnpm run help:build
          postBuild:
            commands:
              - echo END OF HELP BUILD
        artifacts:
          # Base directory should just be next. If you set it to apps/someapp when the build finishes it would then be apps/someapp/apps/someapp/.next and that is wrong.
          baseDirectory: .next
          files:
            - "**/*"
        cache:
          paths:
            - node_modules/**/*

### Log output

<details>

Logs

                             # Starting phase: preBuild
                             # Executing command: echo FRONTEND HELP PREBUILD
                             FRONTEND HELP PREBUILD
                             # Executing command: cd ../../

2022-12-05T21:13:44.852Z [INFO]: # Executing command: nvm install 16.13 2022-12-05T21:13:45.481Z [WARNING]: v16.13.2 is already installed. 2022-12-05T21:13:56.774Z [INFO]: Now using node v16.13.2 (npm v8.1.2) 2022-12-05T21:13:56.776Z [INFO]: Installing default global packages from /root/.nvm/default-packages... npm install -g --quiet yarn@1.22.0 2022-12-05T21:13:59.290Z [INFO]: changed 1 package, and audited 2 packages in 2s 2022-12-05T21:13:59.290Z [INFO]: found 0 vulnerabilities 2022-12-05T21:13:59.300Z [INFO]: # Executing command: nvm use 16 2022-12-05T21:13:59.660Z [INFO]: Now using node v16.18.1 (npm v8.19.2) 2022-12-05T21:13:59.660Z [INFO]: # Executing command: node -v 2022-12-05T21:13:59.663Z [INFO]: v16.18.1 2022-12-05T21:13:59.663Z [INFO]: # Executing command: echo -e "@oxygen:registry=https://registry.npmjs.org/\nstrict-peer-dependencies=false\nauto-install-peers=true\nshamefully-hoist=true" > .npmrc 2022-12-05T21:13:59.663Z [INFO]: # Completed phase: preBuild

Starting phase: build

                             # Executing command: echo FRONTEND HELP BUILD
                             FRONTEND HELP BUILD

2022-12-05T21:13:59.664Z [INFO]: # Executing command: ./scripts/clean.sh 2022-12-05T21:14:30.483Z [INFO]: # Executing command: nvm install 16.13 2022-12-05T21:14:31.111Z [WARNING]: v16.13.2 is already installed. 2022-12-05T21:14:31.415Z [INFO]: Now using node v16.13.2 (npm v8.1.2) 2022-12-05T21:14:31.415Z [INFO]: Installing default global packages from /root/.nvm/default-packages... npm install -g --quiet yarn@1.22.0 2022-12-05T21:14:31.989Z [INFO]: changed 1 package, and audited 2 packages in 463ms 2022-12-05T21:14:31.990Z [INFO]: found 0 vulnerabilities 2022-12-05T21:14:32.000Z [INFO]: # Executing command: nvm use 16 2022-12-05T21:14:32.378Z [INFO]: Now using node v16.18.1 (npm v8.19.2) 2022-12-05T21:14:32.378Z [INFO]: # Executing command: node -v 2022-12-05T21:14:32.381Z [INFO]: v16.18.1 2022-12-05T21:14:32.381Z [INFO]: # Executing command: npx pnpm install 2022-12-05T21:14:33.416Z [WARNING]: npm 2022-12-05T21:14:33.416Z [WARNING]: WARN exec The following package was not found and will be installed: pnpm@7.18.0 2022-12-05T21:14:34.396Z [INFO]: Scope: all 7 workspace projects 2022-12-05T21:14:34.740Z [INFO]: Progress: resolved 1, reused 0, downloaded 0, added 0 2022-12-05T21:14:35.748Z [INFO]: Progress: resolved 25, reused 0, downloaded 8, added 0 2022-12-05T21:14:36.753Z [INFO]: Progress: resolved 42, reused 0, downloaded 25, added 0 2022-12-05T21:14:37.754Z [INFO]: Progress: resolved 55, reused 0, downloaded 36, added 0 2022-12-05T21:14:38.266Z [INFO]: packages/design-system |  WARN  deprecated rollup-plugin-terser@7.0.2 2022-12-05T21:14:38.757Z [INFO]: Progress: resolved 70, reused 0, downloaded 52, added 0 2022-12-05T21:14:39.767Z [INFO]: Progress: resolved 95, reused 0, downloaded 72, added 0 2022-12-05T21:14:40.771Z [INFO]: Progress: resolved 109, reused 0, downloaded 92, added 0 2022-12-05T21:14:41.775Z [INFO]: Progress: resolved 125, reused 0, downloaded 109, added 0 2022-12-05T21:14:42.777Z [INFO]: Progress: resolved 151, reused 0, downloaded 136, added 0 2022-12-05T21:14:43.781Z [INFO]: Progress: resolved 194, reused 0, downloaded 165, added 0 2022-12-05T21:14:44.793Z [INFO]: Progress: resolved 202, reused 0, downloaded 173, added 0 2022-12-05T21:14:45.832Z [INFO]: Progress: resolved 217, reused 0, downloaded 186, added 0 2022-12-05T21:14:46.838Z [INFO]: Progress: resolved 232, reused 0, downloaded 200, added 0 2022-12-05T21:14:47.840Z [INFO]: Progress: resolved 262, reused 0, downloaded 227, added 0 2022-12-05T21:14:48.277Z [INFO]: packages/design-system |  WARN  deprecated @types/cssnano@5.1.0 2022-12-05T21:14:48.844Z [INFO]: Progress: resolved 293, reused 0, downloaded 258, added 0 2022-12-05T21:14:49.846Z [INFO]: Progress: resolved 333, reused 0, downloaded 292, added 0 2022-12-05T21:14:50.859Z [INFO]: Progress: resolved 381, reused 0, downloaded 329, added 0 2022-12-05T21:14:51.860Z [INFO]: Progress: resolved 413, reused 0, downloaded 362, added 0 2022-12-05T21:14:52.850Z [INFO]: apps/help |  WARN  deprecated sourcemap-codec@1.4.8 2022-12-05T21:14:52.864Z [INFO]: Progress: resolved 450, reused 0, downloaded 397, added 0 2022-12-05T21:14:53.458Z [INFO]: apps/main |  WARN  deprecated uuid@3.4.0 2022-12-05T21:14:53.865Z [INFO]: Progress: resolved 493, reused 0, downloaded 438, added 0 2022-12-05T21:14:54.050Z [INFO]: apps/main |  WARN  deprecated uuid@3.3.2 2022-12-05T21:14:54.777Z [INFO]: apps/main |  WARN  deprecated @aws-sdk/eventstream-marshaller@3.6.1 2022-12-05T21:14:54.871Z [INFO]: Progress: resolved 515, reused 0, downloaded 461, added 0 2022-12-05T21:14:55.789Z [INFO]: apps/main |  WARN  deprecated @aws-sdk/util-base64-browser@3.6.1 2022-12-05T21:14:55.806Z [INFO]: apps/main |  WARN  deprecated @aws-sdk/util-base64-node@3.6.1 2022-12-05T21:14:55.871Z [INFO]: Progress: resolved 555, reused 0, downloaded 495, added 0 2022-12-05T21:14:56.881Z [INFO]: Progress: resolved 578, reused 0, downloaded 526, added 0 2022-12-05T21:14:57.883Z [INFO]: Progress: resolved 618, reused 0, downloaded 555, added 0 2022-12-05T21:14:58.887Z [INFO]: Progress: resolved 675, reused 0, downloaded 612, added 0 2022-12-05T21:14:59.889Z [INFO]: Progress: resolved 798, reused 0, downloaded 705, added 0 2022-12-05T21:15:00.893Z [INFO]: Progress: resolved 884, reused 0, downloaded 786, added 0 2022-12-05T21:15:01.217Z [INFO]: apps/main |  WARN  deprecated @aws-sdk/util-base64-browser@3.186.0 2022-12-05T21:15:01.218Z [INFO]: apps/main |  WARN  deprecated @aws-sdk/util-base64-node@3.186.0 2022-12-05T21:15:01.892Z [INFO]: Progress: resolved 957, reused 0, downloaded 864, added 0 2022-12-05T21:15:02.892Z [INFO]: Progress: resolved 1013, reused 0, downloaded 913, added 0 2022-12-05T21:15:03.893Z [INFO]: Progress: resolved 1128, reused 0, downloaded 1015, added 0 2022-12-05T21:15:04.893Z [INFO]: Progress: resolved 1239, reused 0, downloaded 1122, added 0 2022-12-05T21:15:05.565Z [INFO]: apps/main |  WARN  deprecated querystring@0.2.0 2022-12-05T21:15:05.893Z [INFO]: Progress: resolved 1340, reused 0, downloaded 1222, added 0 2022-12-05T21:15:06.893Z [INFO]: Progress: resolved 1432, reused 0, downloaded 1302, added 0 2022-12-05T21:15:07.425Z [INFO]: packages/design-system |  WARN  deprecated stable@0.1.8 2022-12-05T21:15:07.894Z [INFO]: Progress: resolved 1526, reused 0, downloaded 1391, added 0 2022-12-05T21:15:08.941Z [INFO]: Progress: resolved 1568, reused 0, downloaded 1481, added 0 2022-12-05T21:15:09.947Z [INFO]: Progress: resolved 1617, reused 0, downloaded 1524, added 0 2022-12-05T21:15:10.961Z [INFO]: Progress: resolved 1670, reused 0, downloaded 1580, added 0 2022-12-05T21:15:12.033Z [INFO]: Progress: resolved 1756, reused 0, downloaded 1657, added 0 2022-12-05T21:15:13.034Z [INFO]: Progress: resolved 1851, reused 0, downloaded 1738, added 0 2022-12-05T21:15:13.123Z [INFO]: apps/main |  WARN  deprecated uglify-es@3.3.9 2022-12-05T21:15:13.286Z [INFO]: apps/main |  WARN  deprecated source-map-resolve@0.5.3 2022-12-05T21:15:13.444Z [INFO]: apps/main |  WARN  deprecated resolve-url@0.2.1 2022-12-05T21:15:13.461Z [INFO]: apps/main |  WARN  deprecated source-map-url@0.4.1 2022-12-05T21:15:13.475Z [INFO]: apps/main |  WARN  deprecated urix@0.1.0 2022-12-05T21:15:14.277Z [INFO]: Progress: resolved 1937, reused 0, downloaded 1847, added 0 2022-12-05T21:15:14.294Z [INFO]: Packages: +1905 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2022-12-05T21:15:15.405Z [INFO]: Progress: resolved 1937, reused 0, downloaded 1848, added 0 2022-12-05T21:15:15.518Z [INFO]: Packages are hard linked from the content-addressable store to the virtual store. Content-addressable store is at: /codebuild/output/.pnpm-store/v3 Virtual store is at: node_modules/.pnpm 2022-12-05T21:15:16.405Z [INFO]: Progress: resolved 1937, reused 0, downloaded 1895, added 137 2022-12-05T21:15:17.406Z [INFO]: Progress: resolved 1937, reused 0, downloaded 1895, added 164 2022-12-05T21:15:18.445Z [INFO]: Progress: resolved 1937, reused 0, downloaded 1895, added 165 2022-12-05T21:15:19.445Z [INFO]: Progress: resolved 1937, reused 0, downloaded 1897, added 473 2022-12-05T21:15:20.444Z [INFO]: Progress: resolved 1937, reused 0, downloaded 1898, added 769 2022-12-05T21:15:21.449Z [INFO]: Progress: resolved 1937, reused 0, downloaded 1898, added 1108 2022-12-05T21:15:22.449Z [INFO]: Progress: resolved 1937, reused 0, downloaded 1898, added 1564 2022-12-05T21:15:23.459Z [INFO]: Progress: resolved 1937, reused 0, downloaded 1898, added 1844 2022-12-05T21:15:24.459Z [INFO]: Progress: resolved 1937, reused 0, downloaded 1898, added 1904 2022-12-05T21:15:26.172Z [INFO]: Progress: resolved 1937, reused 0, downloaded 1899, added 1904 2022-12-05T21:15:26.472Z [INFO]: .../node_modules/core-js-pure postinstall$ node -e "try{require('./postinstall')}catch(e){}" 2022-12-05T21:15:26.513Z [INFO]: .../swiper@8.4.5/node_modules/swiper postinstall$ node -e "try{require('./postinstall')}catch(e){}" 2022-12-05T21:15:26.554Z [INFO]: .../node_modules/core-js-pure postinstall: Thank you for using core-js ( https://github.com/zloirock/core-js ) for polyfilling JavaScript standard library! 2022-12-05T21:15:26.556Z [INFO]: .../node_modules/core-js-pure postinstall: The project needs your help! Please consider supporting of core-js: .../node_modules/core-js-pure postinstall: > https://opencollective.com/core-js .../node_modules/core-js-pure postinstall: > https://patreon.com/zloirock .../node_modules/core-js-pure postinstall: > bitcoin: bc1qlea7544qtsmj2rayg0lthvza9fau63ux0fstcz .../node_modules/core-js-pure postinstall: Also, the author of core-js ( https://github.com/zloirock ) is looking for a good job -) 2022-12-05T21:15:26.558Z [INFO]: .../node_modules/core-js-pure postinstall: Done 2022-12-05T21:15:26.670Z [INFO]: .../swiper@8.4.5/node_modules/swiper postinstall: Done 2022-12-05T21:15:26.710Z [INFO]: .../node_modules/maplibre-gl postinstall$ node ./postinstall.js 2022-12-05T21:15:26.794Z [INFO]: .../node_modules/maplibre-gl postinstall: Done 2022-12-05T21:15:27.136Z [INFO]: .../.pnpm/turbo@1.6.3/node_modules/turbo postinstall$ node install.js 2022-12-05T21:15:27.137Z [INFO]: .../esbuild@0.15.18/node_modules/esbuild postinstall$ node install.js 2022-12-05T21:15:27.196Z [INFO]: Progress: resolved 1937, reused 0, downloaded 1899, added 1905, done 2022-12-05T21:15:27.229Z [INFO]: .../.pnpm/turbo@1.6.3/node_modules/turbo postinstall: Done 2022-12-05T21:15:27.305Z [INFO]: .../esbuild@0.15.18/node_modules/esbuild postinstall: Done 2022-12-05T21:15:29.220Z [INFO]: devDependencies:



</details>

### Additional information

_No response_
DuCanhGH commented 1 year ago

@thijsdaniels yeah, it's probably so that your monorepo's root's files don't conflict with your app's ones. I mean, stuffs like node_modules and package.json from your monorepo's root will probably be copied, and so are your app's ones. Edit: deleted all the nft.json stuff because I don't think it makes a lot of sense.

lephuongbg commented 1 year ago

@thijsdaniels Does asset files work normally in your workaround?

In my case, the workaround doesn't work due to conflict in the app's node_modules and base folder's node_modules. I make my build "work" by adding echo 'require("./apps/storefront/server.js")' > .next/standalone/server.js after build command, and the SSR actually works, except now all _next/static/* also triggered SSR (and returned 404 page as a result), instead of get served statically.

@hloriana Do you have any update on why static assets doesn't work, even though the output folder structure is the same? i.e .next/static. My app ID is dnynwlrmvtihb.

DuCanhGH commented 1 year ago

@lephuongbg probably because that folder is at .next/standalone/your_app/static, rather than what aws-amplify expected to see, which is probably .next/standalone/static? Just my guesswork, btw.

lephuongbg commented 1 year ago

@DuCanhGH static asset folder is always .next/static though, for both single repo & monorepos.

DuCanhGH commented 1 year ago

@lephuongbg oh, yeah that's true. Maybe you can try copying that folder to .next/standalone/[your_app] instead?

lephuongbg commented 1 year ago

Finally make it works. Basically had to:

  1. Disable pnpm symlinking node_modules by having node-linker=hoisted in project root's .npmrc. Without this, step 3 is impossible.
  2. Make sure outputFileTracingRoot: path.join(__dirname, '../..') is set correctly in next.config.js. Otherwise, build output won't contain all necessary dependencies.
  3. After build, shoehorn the mono-repos' .next/standalone structure to make it look like single-repo .next/standalone. My command is similar to https://github.com/aws-amplify/amplify-hosting/issues/3179#issuecomment-1357930988 but uses rsync to be on the safe-side when merging .next/standalone/[app]/node_modules and .next/standalone/node_modules:
build:
  commands:
    - cd ../.. && pnpm run build:storefront && cd apps/storefront
    - rsync .next/standalone/apps/storefront/ .next/standalone/ -a --copy-links -v && rm -r .next/standalone/apps
appRoot: apps/storefront
Rafcin commented 1 year ago

I'm going to try this out once I can fix my console, for some reason now I'm getting network failures when trying to list amplify apps. One issues fixed and 100 more take its place.

king0120 commented 1 year ago

Wonder if anyone on the Amplify team has opinions on this? Would be great to know if there was any sort of priority to fix the monorepo issues.

ghost commented 1 year ago

Hello everyone who has been engaged on this issue! 👋🏽 Thank you all for your continued patience. The Amplify team is actively working on supporting the ability to host Next.js apps that use monorepo frameworks and this task is a priority for the team. We will continue to provide updates as we make progress with this task.

chrisl777 commented 1 year ago

@hloriana Thanks for letting us know that the team is looking into monorepo support! 👏

Is there a proposal or central issue requesting feedback for tracking monorepo tooling support?

Also, how soon might there be some resolution? I'm trying to find clear examples of sharing code between apps within my repo, along with using Amplify. I have some pressing projects where I'll need to decide on an approach.

The current Amplify docs have a basic example of using multiple front-end projects, but does not appear to address sharing code between them.

Also, it seems odd to attach or instantiate Amplify to one front-end project, as the docs seem to suggest. Rather, it would be nice if the backend was another "package" within the monorepo, and API files could more readily be shared (along with sharing common wrappers that we write for those APIs).

The options out there appear to be yarn workspaces, along with Lerna, Nx, Turborepo, etc. It would be super amazing to have some clear docs and examples!

ScottAwesome commented 1 year ago

Hello everyone who has been engaged on this issue! 👋🏽 Thank you all for your continued patience. The Amplify team is actively working on supporting the ability to host Next.js apps that use monorepo frameworks and this task is a priority for the team. We will continue to provide updates as we make progress with this task.

@hloriana Any updates on this? Its been over a month now and I haven't seen any movement on this, we are considering lift and shifting our entire frontend to outside AWS services as a result, the features around Amplify hosting and this specifically are extremely limiting and its starting to feel like Amazon is slowly abandoning the product line

michrome commented 1 year ago

Hey @chrisl777 @lephuongbg @thijsdaniels @king0120 @Rafcin @jbreemhaar @ScottAwesome @DuCanhGH @hloriana 👋

Work to better support monorepos is underway and we're looking for volunteers to help test we're heading in the right direction. If you're interested in testing a beta with an app that's part of a monorepo, please reach out to me at jrm@amazon.com. We'd particularly appreciate hearing from npm workspace, yarn workspace, pnpm workspace and NX workspace users. Thanks!

Rafcin commented 1 year ago

@michrome I've built some personal monorepo apps that gave even Vercel a stroke to deploy. I'm down to test this new system out! I'll shoot you an email!

ryankauk commented 1 year ago

Took a whole lot of tinkering, but I finally got it.

This is what worked for me

Using:

const nextConfig = { reactStrictMode: true, swcMinify: true, experimental: { appDir: true, }, // ignore these for now to speed up debugging builds eslint: { ignoreDuringBuilds: true }, typescript: { ignoreBuildErrors: true } }

module.exports = nextConfig


- build spec:
```yaml
version: 1
applications:
  - appRoot: apps/frontend/amplify-next
    # not quite sure what the env.variables do but they don't get passed into next build with process.env. They must get added somewhere else
    env:
      variables: {}
    frontend:
      phases:
        preBuild:
          commands:
            - npm install -g pnpm
            - sh -c 'cd ../../.. && pnpm config set store-dir ./.pnpm-store'
            - pnpm install --prefer-offline --filter=amplify-next
        build:
          commands:
            - sh -c 'cd ../../.. && pnpm turbo run build --filter=amplify-next'
            - cp -r .next/static .next/standalone/apps/frontend/amplify-next/.next/static
            - cp -r public .next/standalone/apps/frontend/amplify-next/public
            - echo 'require("./apps/frontend/amplify-next/server.js")' > .next/standalone/server.js
      artifacts:
        baseDirectory: .next
        files:
          - "**/*"
      cache:
        # not matter what you set for appRoot or AMPLIFY_MONOREPO_APP_ROOT cache is always relative to your applications root directory 
        paths:
          - .pnpm-store/**/*
          # - node_modules/.cache/turbo/**/*
AMPLIFY_MONOREPO_APP_ROOT apps/frontend/amplify-next All branches

NEXT_PRIVATE_STANDALONE seems to be auto injected and nextjs automatically picks this up so nothing is really needed here

AMPLIFY_MONOREPO_APP_ROOT from the docs, is supposedly supposed to be set automatically when you set appRoot but it does not. Without this in this particular spot I would get the error The base directory '.next' you have specified in your amplify.yml does not exist. Make sure you run 'next build' or specify the correct name for your NextJS build directory. even with all the above build spec.

Last outstanding issue

Rafcin commented 1 year ago

Idk if this is done behind the scenes, we should create a directory on amplify-hosting and add a bunch of different example repos that should be deployed by Amplify and redeployed each time there's an update to confirm what works and what doesn't.

tqhoughton commented 1 year ago

I also struggled with this but was able to get things working using:

turbo@1.8.3 yarn@1.22.19

with my web app located in apps/web

and the following amplify.yml config (thanks to @thijsdaniels for the help with the post build script)

version: 1
applications:
  - frontend:
      phases:
        preBuild:
          commands:
            - yarn install
        build:
          commands:
            - yarn build
        postBuild:
          commands:
            # this copies the files back to the root of the "standalone" folder so Amplify can find them
            # keep an eye on https://github.com/aws-amplify/amplify-hosting/issues/3179
            # for possible long-term fix from the Amplify team
            - cp -r .next/standalone/apps/web/. .next/standalone
      artifacts:
        baseDirectory: .next
        files:
          - '**/*'
      cache:
        paths:
          - node_modules/**/*
    appRoot: apps/web

I also had to add output: 'standalone' to my next.config.js since it wasn't there originally.

zaytsevandrii commented 1 year ago

I also have problems using AWS Amplify, my e-commerce site works well on verсel, and on AWS pages where data is loaded from the mongo database there are often 500 error, I even tried to change the code from SSR(getServerSideProps) to Useeffect

MANTENN commented 1 year ago

It used to work with: cp -r apps/app-name/.next/standalone/apps/app-name/ apps/app-name/.next/standalone/ cp -r apps/app-name/.next/standalone/apps/app-name/* apps/app-name/.next/standalone/ without .next folder in the .next/standalone folder

seems like there was an update today that broke our builds—without a warning or a heads up. updated to: cp -r apps/app-name/.next/standalone/apps/app-name/. and added for static files: cp -r apps/app-name/.next/static/. apps/app-name/.next/standalone/.next/static.

context:

version: 1
applications:
  - frontend:
      phases:
        preBuild:
          commands:
            - npx npm install
        build:
          commands:
            - npx turbo run build --filter=apps/app-name
            - cp -r apps/app-name/.next/standalone/apps/app-name/. apps/app-name/.next/standalone/
             - cp -r apps/app-name/.next/standalone/apps/app-name/* apps/app-name/.next/standalone/
            - cp -r apps/app-name/.next/static/. apps/app-name/.next/standalone/.next/static
      artifacts:
        baseDirectory: apps/app-name/.next
        files:
          - '**/*'
      cache:
        paths:
          - node_modules/**/*
      buildPath: /
    appRoot: apps/app-name
victorccccc commented 1 year ago

Hi 👋 @MANTENN, We are gradually onboarding customers to use our new web compute & monorepo feature. Can you please share your appId so we can investigate further? You can also send it to [REDACTED]

Thanks

vashisth00 commented 1 year ago

So I have this issue in just amplify

I have a root-folder

Now my base_url runs on next-app-2 and next-app-1 should run as base_url/app

Same thing works on EC2 with turbo setup such as with deploy.sh like

cd root-app/ sudo git checkout . sudo git pull origin development sudo git stash pop sudo yarn install sudo yarn build sudo pm2 kill -a sudo NODE_ENV=production pm2 --name trybeem start "yarn workspace web-main -- start" sudo NODE_ENV=production pm2 --name trybeem start "yarn workspace web-app -- start --port 3001" exit

What to do in amplify to make it work

victorccccc commented 1 year ago

We have provided the support for Compute + Monorepo frameworks.

FAQ link: https://github.com/aws-amplify/amplify-hosting/blob/main/FAQ.md#support-for-monorepo-framework

Please feel free to create new issue if you have additional question.

Thanks

github-actions[bot] commented 1 year ago

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.

github-actions[bot] commented 1 year ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.