aws-amplify / aws-amplify/amplify-hosting
Error: Command failed with ENOENT: node_modules/.bin/next build
- 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-console/blob/master/FAQ.md).
- [X] I have [searched for duplicate or closed issues](https://github.com/aws-amplify/amplify-console/issues?q=is%3Aissue+).
- [X] I have read the guide for [submitting bug reports](https://github.com/aws-amplify/amplify-console/blob/master/CONTRIBUTING.md).
- [X] I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
### App Id
d3b0hwg64oxpr5
### Region
us-east-2
### Amplify Console feature
Monorepo
### Describe the bug
During the deployment Build step I am getting the following error
```
2021-10-31T02:48:53.959Z [INFO]: Starting SSR Build...
2021-10-31T02:50:15.687Z [ERROR]: Error: Command failed with ENOENT: node_modules/.bin/next build
```
This seems to be caused by the way yarn workspaces installs bin dependencies.
In my monorepo I have an apps directory with a default next.js application located at `apps/my-app`. My pre build steps to install dependencies are `yarn set version berry` and `yarn install`. This leaves the .bin/next file in the root at /node_modules/.bin/next instead of /apps/my-app/node_modules/.bin/next.
I have tried to get around this by adding the following pre build commands **without** success
```
- rm -rf ./node_modules/.bin
- ln -s ../../node_modules/.bin node_modules
```
### Expected behavior
Some way to point to point to the .bin/next executable located in the project root node_modules directory.
### Reproduction steps
Deploy a next.js monorepo app using yarn workspaces
### Build Settings
```yaml
version: 1
applications:
- appRoot: apps/my-app
backend:
phases:
build:
commands:
- '# Execute Amplify CLI with the helper script'
- amplifyPush --simple
frontend:
phases:
preBuild:
commands:
- yarn set version berry
- yarn install
build:
commands:
- rm -rf ./node_modules/.bin
- ln -s ../../node_modules/.bin node_modules
- yarn build
artifacts:
baseDirectory: .next
files:
- '**/*'
cache:
paths:
- node_modules/**/*
```
```
### Additional information
_No response_
Contributor guide
Research direction
Start with the provided Amplify build settings and deployment log, focusing on the apps/my-app appRoot, Yarn Berry install, and yarn build command. Reproduce a Next.js monorepo deployment and investigate how the build step resolves node_modules/.bin/next. Done means the deployment can locate and run the root .bin/next executable without the unsuccessful symlink workaround.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- next.js, node.js
- Domain
- ci-cd, cloud
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100