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
459 stars 116 forks source link

pnpm workspaces not working #3786

Open Lezzio opened 12 months ago

Lezzio commented 12 months ago

Before opening, please confirm:

App Id

d3q127va4gyote

AWS Region

us-east-1

Amplify Hosting feature

Deployments, Frontend builds, Monorepo

Frontend framework

Next.js

Next.js version

13.1.5

Next.js router

Pages Router

Describe the bug

We're building and deploying a NextJS application on Amplify. We have a NX monorepo, and our NextJS app depends on local packages that we add thanks to pnpm workspaces. However, as per our observation and the documentation, the linkage is done using symlinks which isn't correctly supported by Amplify.

https://docs.npmjs.com/cli/v7/using-npm/workspaces https://pnpm.io/fr/cli/link

Example: app is the NextJS application, it depends on the package 'some-dependency' locally => Runtime error thrown: Cannot find module 'some-dependency'

Expected behavior

We expect pnpm workspaces to work with its symbolical linkage Would you know of any alternative?

Reproduction steps

  1. Create a pnpm workspace dependency to your NextJS app
  2. Run

Build Settings

version: "1.0"
applications:
  - appRoot: apps/campus
    frontend:
      phases:
        preBuild:
          commands:
            - echo "node-linker=hoisted" >> .npmrc
            - echo "//npm.pkg.github.com/:_authToken=[GITHUB_TOKEN]" >> .npmrc
            - corepack enable
            - corepack prepare pnpm@8.3.1 --activate
            - export NODE_OPTIONS=--max-old-space-size=8192
            - pnpm install --shamefully-hoist --ignore-script
            - cd ../..
            - pnpm package
            - cd apps/campus
        build:
          commands:
            - env | grep -E '[SENSITIVE_VARIABLES]' >> .env.production
            - pnpm build --no-lint
      artifacts:
        baseDirectory: .next
        files:
          - "**/*"
        discard-paths: "yes"
        exclude-paths:
          - "**/cache/**/*"

Log output

``` # Put your logs below this line ```

Additional information

No response

fimbres commented 5 months ago

I'm running into the same issue, any luck on this one? @Lezzio