aws-amplify / aws-amplify/amplify-hosting

pnpm workspaces not working

Open
#3,786 1 comment 3 reactions 0 assignees View on GitHub
pending-triage
Dominant language
Dockerfile
Stars
481
Forks
123
PR merge metrics
No merged PRs in 30d

Description

### Before opening, please confirm:

- [X] I have checked to see if my question is addressed in the [FAQ](https://github.com/aws-amplify/amplify-hosting/blob/master/FAQ.md).
- [X] I have [searched for duplicate or closed issues](https://github.com/aws-amplify/amplify-hosting/issues?q=is%3Aissue+).
- [X] I have read the guide for [submitting bug reports](https://github.com/aws-amplify/amplify-hosting/blob/master/CONTRIBUTING.md).
- [X] I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
- [X] I have removed any sensitive information from my code snippets and submission.

### 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

```yaml
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_

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the Amplify Hosting deployment described in the issue, using the provided applications build settings and pnpm workspace dependency. Investigate the reported Cannot find module error; done means the local workspace package resolves during the Next.js build and deployment.

Written by the indexing model from the issue text.

Assessment

Tech stack
next.js
Domain
ci-cd, devops
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.